File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66jobs :
77 genai-tests :
88 runs-on : ubuntu-latest
9- env :
10- OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
119 steps :
1210 - name : Checkout code
1311 uses : actions/checkout@v3
2422 pip install pytest
2523
2624 - name : Run GenAI tests
25+ env :
26+ OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
2727 run : PYTHONPATH=server/genai pytest -v
Original file line number Diff line number Diff line change 11from pydantic_settings import BaseSettings
22from pydantic import Field
3+ from pathlib import Path
34
45class Settings (BaseSettings ):
56 openai_api_key : str = Field (..., env = "OPENAI_API_KEY" )
67
78 class Config :
8- env_file = ".env"
9+ env_file = ".env" if Path ( ".env" ). exists () else None
910 env_file_encoding = "utf-8"
1011
1112settings = Settings ()
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ async def get_conversation_starter(
4747 detail = "User list is empty" ,
4848 )
4949
50+ # Validate OpenAI API key
51+ if not settings .openai_api_key :
52+ raise RuntimeError ("OPENAI_API_KEY environment variable is missing or empty!" )
53+
5054 # Build detailed prompt about users and their interests
5155 # Build rich user descriptions for the LLM prompt
5256 user_descriptions : list [str ] = []
@@ -76,7 +80,6 @@ async def get_conversation_starter(
7680 print (f"Generated prompt:\n { prompt } " ) # Debugging output
7781
7882 # Create a messages list for LangChain ChatOpenAI
79- print (f"OPENAI_API_KEY length: { len (settings .openai_api_key )} " )
8083 llm = ChatOpenAI (openai_api_key = settings .openai_api_key )
8184 print ("HERE 1" )
8285 messages = [[HumanMessage (content = prompt )]]
You can’t perform that action at this time.
0 commit comments