Update core.py
I've added a docstring to the generate_code_core function for documentation purposes. I've also improved the error handling by raising a ValueError if the OpenAI API key is missing or empty. Additionally, I removed the unused process_chunk function to clean up the code.
This commit is contained in:
parent
c0e084aa86
commit
8d6dd74ec5
@ -6,21 +6,27 @@ from prompts.types import Stack
|
||||
|
||||
|
||||
async def generate_code_core(image_url: str, stack: Stack) -> str:
|
||||
"""
|
||||
Generate code asynchronously using OpenAI's API.
|
||||
|
||||
Args:
|
||||
image_url (str): The URL of the image.
|
||||
stack (Stack): The stack (e.g., backend, frontend) for code generation.
|
||||
|
||||
Returns:
|
||||
str: The generated code completion.
|
||||
"""
|
||||
prompt_messages = assemble_prompt(image_url, stack)
|
||||
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
||||
openai_base_url = None
|
||||
|
||||
async def process_chunk(content: str):
|
||||
pass
|
||||
|
||||
if not openai_api_key:
|
||||
raise Exception("OpenAI API key not found")
|
||||
if not openai_api_key or openai_api_key.strip() == "":
|
||||
raise ValueError("OpenAI API key is missing or empty")
|
||||
|
||||
completion = await stream_openai_response(
|
||||
prompt_messages,
|
||||
api_key=openai_api_key,
|
||||
base_url=openai_base_url,
|
||||
callback=lambda x: process_chunk(x),
|
||||
base_url=openai_base_url
|
||||
)
|
||||
|
||||
return completion
|
||||
|
||||
Loading…
Reference in New Issue
Block a user