Skip to content

Commit

Permalink
fix: Choose correct way to generate based on model name
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed May 28, 2024
1 parent fd57e31 commit e8c5aad
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions agents-api/agents_api/rec_sum/generate.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from openai import AsyncClient
from tenacity import retry, stop_after_attempt, wait_fixed


client = AsyncClient()
from agents_api.env import model_inference_url, model_api_key
from agents_api.model_registry import JULEP_MODELS
from litellm import acompletion


@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
async def generate(
messages: list[dict],
client: AsyncClient = client,
model: str = "gpt-4-turbo",
**kwargs
**kwargs,
) -> dict:
result = await client.chat.completions.create(
model=model, messages=messages, **kwargs
)
base_url, api_key = None, None
if model in JULEP_MODELS:
base_url, api_key = model_inference_url, model_api_key
model = f"openai/{model}"

result = result.choices[0].message.__dict__
result = await acompletion(
model=model,
messages=messages,
base_url=base_url,
api_key=api_key,
)

return result
return result.choices[0].message.json()

0 comments on commit e8c5aad

Please sign in to comment.