File size: 1,330 Bytes
ed83bfd
 
 
 
 
 
ece0f5f
 
 
 
ed83bfd
 
 
 
 
 
 
 
 
 
 
ece0f5f
 
ed83bfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from dotenv import load_dotenv
from typing import Optional
from langchain_openai import ChatOpenAI


# import inspect
# load_dotenv(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) , '.env'))

load_dotenv()
class MyChatOpenAI:
    @classmethod
    def from_model(
        cls, 
        model: str = 'gpt-4o-mini',
        *,
        langsmith_project: str = 'default',
        temperature: float = 0.7,
        max_tokens: Optional[int] = 4096,
        max_retries: int = 1,
        **kwargs
        )-> ChatOpenAI:        

        if model in ['gpt-4o', 'GPT-4o', 'GPT-4O', 'gpt-4O', 'gpt4o', 'GPT4o', 'GPT4O', 'gpt4O']:
            model = 'gpt-4o'
        elif model in ['gpt-4o-mini', 'GPT-4o-mini', 'GPT-4O-mini', 'gpt-4O-mini', 'gpt4o-mini', 'GPT4o-mini', 'GPT4O-mini', 'gpt4O-mini', 'gpt4omini', 'GPT4omini', 'GPT4Omini', 'gpt4Omini']:
            model = 'gpt-4o-mini'
        else:
            raise ValueError(f"Model {model} is currently not supported. Supported models are: ['gpt-4o', 'gpt-4o-mini']")

        
        return ChatOpenAI(
            openai_api_key=os.getenv("OPENAI_API_KEY"), 
            model=model,
            temperature=temperature,
            max_tokens=max_tokens,
            max_retries=max_retries,
            **kwargs
            )