CoolFace
Apppublic

ranjangoel/GPT-PDF

sourceHugging Faceupdated 4y agoView on Hugging Face
5likes
model_interface.py33 linesDownload Raw Back to gpt_reader
1from typing import List2import openai3 4 5class ModelInterface(object):6 7    def __init__(self) -> None:8        pass9 10    def send_msg(self, *args):11        pass12 13 14class OpenAIModel(object):15 16    def __init__(self, api_key, model='gpt-3.5-turbo', temperature=0.2) -> None:17        openai.api_key = api_key18        self.model = model19        self.temperature = temperature20 21    def send_msg(self, msg: List[dict], return_raw_text=True):22        23        response = openai.ChatCompletion.create(24            model=self.model,25            messages=msg,26            temperature=self.temperature27        )28 29        if return_raw_text:30            return response["choices"][0]["message"]["content"]31        else:32            return response33