File size: 722 Bytes
9beb013
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from openai import OpenAI

def get_models(api_key):
    client = OpenAI(api_key=api_key)
    models = client.models.list()
    models = sorted([model.id for model in models.data if model.id.startswith("gpt")])
    return models

def query(api_key, reviews: list, model: str = "gpt-3.5-turbo"):
    client = OpenAI(api_key=api_key)
    message = str(reviews) + "\n\nAnalyze and provide a structured summary of both the positive and negative features of the hotel based on the above reviews. Quantify the frequency of each aspect mentioned in the reviews."
    stream = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": message}],
        stream=True,
    )
    return stream