gadkins
adding envs explicitly
31f72dd
raw
history blame contribute delete
No virus
1.34 kB
from openai import OpenAI
import os
import time
# from dotenv import dotenv_values
# Load model and API endpoint from environment variables
# config = dotenv_values(".env")
# model = config.get("MODEL")
# api_endpoint = config.get("API_ENDPOINT")
model = "casperhansen/mixtral-instruct-awq"
api_endpoint = "https://irlgzb4izhczxt-8000.proxy.runpod.net"
openai_api_base = api_endpoint + '/v1'
# Initialize the OpenAI client
client = OpenAI(
api_key="EMPTY", # Replace with your actual API key if required
base_url=openai_api_base,
)
def chat_completion_request(input):
messages = [
{"role": "user", "content": f"{input}"},
]
# Create chat completions using the OpenAI client
chat_response = client.chat.completions.create(
model=model,
messages=messages,
temperature=0,
max_tokens=500
)
# Extract the completion text from the response
if chat_response.choices:
completion_text = chat_response.choices[0].message.content
else:
completion_text = None
return completion_text
# # Test the function
# messages = [
# {"role": "user", "content": "Write a long essay on the topic of spring."}
# ]
# chat_response = chat_completion_request_openai(messages, client)
# messages.append({"role": "assistant", "content": chat_response})