Parameters and LLM settings in crewai v0.61.0

import os
from dotenv import load_dotenv
load_dotenv()
os.environ[“OPENAI_API_KEY”] = os.getenv(“OPENAI_API_KEY”)
os.environ[“temperature”] = “0.0”
os.environ[“top_p”] = “0.1”

In the agent settings, set llm = ‘gpt-4o-mini-2024-07-18’

Is this setup correct for the API key and parameters like temperature and top_p?

Im still looking into whats the correct way, please bare with

1 Like

Oh okay, wait for the good news. Thank you so much. I will stick with the older version of Crewai for setting parameters for a while. :pray:

this seems to work for gemini but you have to install google.generativeai and I am going to try the same with openai.

self.gemini_flash = genai.GenerativeModel(model_name=“gemini/gemini-1.5-flash”, generation_config = genai.GenerationConfig(max_output_tokens=8000,temperature=0.3))

1 Like

I think there is a way to do this by editing the LiteLLM yaml files but not sure about the conditions to do it. anyone a LiteLLM expert here. this is getting crazy.

Upgrade to latest version 0.61.3

then you can do this

llm = LLM(
    model="gpt-4",
    temperature=0.8,
    max_tokens=150,
    top_p=0.9,
    frequency_penalty=0.1,
    presence_penalty=0.1,
    stop=["END"],
    seed=42,
    base_url="https://api.openai.com/v1",
    api_key="your-api-key-here"
)
agent = Agent(llm=llm, ...)

Obviously change base url, api and model to your needs

And remove what ever parameters you do not need

@matt this seems to work fine other than for gemini models.

Just tested and works fine for me, whats the issue?

Sorry. It was my mistake.

May I ask, as I’m a bit confused, whether base_url is optional or required in the following code?

from dotenv import load_dotenv
import os
from crewai import LLM
load_dotenv()
gpt4omini = LLM(
model=“gpt-4o-mini-2024-07-18”,
temperature=0.0,
top_p=0.1,
api_key=os.getenv(“OPENAI_API_KEY”)
)

Thank you so much for your help. :pray:

You do not need to set it for OpenAI, you only need to set your API key

Thank you so much! :smiling_face_with_three_hearts:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.