File size: 1,336 Bytes
9abbe21
 
 
31f72dd
9abbe21
 
31f72dd
 
 
 
 
9abbe21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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})