Add initial project structure with .gitignore, pyproject.toml, and main application files
This commit is contained in:
23
src/openai_client.py
Normal file
23
src/openai_client.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import configparser
|
||||
from openai import OpenAI
|
||||
|
||||
class OpenAIClient:
|
||||
def __init__(self):
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read('config/config.ini')
|
||||
self.client = OpenAI(
|
||||
api_key=self.config['openai']['api_key'],
|
||||
base_url=self.config['openai']['base_url']
|
||||
)
|
||||
|
||||
def get_chat_response(self, messages):
|
||||
try:
|
||||
response = self.client.chat.completions.create(
|
||||
model=self.config['openai']['model'],
|
||||
messages=messages,
|
||||
stream=True
|
||||
)
|
||||
return response
|
||||
except Exception as e:
|
||||
raise Exception(f"OpenAI API error: {str(e)}")
|
||||
Reference in New Issue
Block a user