Download src/client.py from VinceAjello/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 546 Bytes
-
https://huggingface.co/spaces/VinceAjello/Final_Assignment_Template/resolve/main/src/client.py
- Command line
-
hf download hf://spaces/VinceAjello/Final_Assignment_Template/src/client.py
-
curl -L -o client.py https://huggingface.co/spaces/VinceAjello/Final_Assignment_Template/resolve/main/src/client.py
546 Bytes
| import os | |
| from openai import OpenAI | |
| api_key = os.getenv("OPENAI_API_KEY") | |
| # client = OpenAI(base_url="http://10.0.0.10:1234/v1", api_key="no") | |
| client = OpenAI(api_key=api_key) | |
| def ask(system, prompt, task_title): | |
| completion = client.chat.completions.create( | |
| model="gpt-4.1-mini", | |
| messages=[ {"role": "system", "content": system}, {"role": "user", "content": prompt}]) | |
| try: | |
| return completion.choices[0].message.content | |
| except Exception as e: | |
| return f"Fail to plan on this task: {task_title} with error: {e}" |