From c3c9d18cfde4fe6953c6133c23d12c89285b6ed6 Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 3 Sep 2023 20:42:54 -0400 Subject: [PATCH] openai class and error cleanups --- example.py | 2 +- swarms/__init__.py | 2 +- swarms/models/__init__.py | 2 +- swarms/models/openai.py | 34 ++++++++++++++++++++++++---------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/example.py b/example.py index 5cce3234..db0a841b 100644 --- a/example.py +++ b/example.py @@ -2,7 +2,7 @@ from swarms import Worker node = Worker( - openai_api_key="", + openai_api_key="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", ai_name="Optimus Prime", ) diff --git a/swarms/__init__.py b/swarms/__init__.py index 65ae8c28..ca61deb1 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -13,6 +13,6 @@ from swarms.models.anthropic import Anthropic from swarms.models.huggingface import HuggingFaceLLM # from swarms.models.palm import GooglePalm from swarms.models.petals import Petals -from swarms.models.openai import OpenAI +from swarms.models.openai import OpenAIChat diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index d5c4ed27..5f0bd0a7 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -2,4 +2,4 @@ from swarms.models.anthropic import Anthropic from swarms.models.huggingface import HuggingFaceLLM # from swarms.models.palm import GooglePalm from swarms.models.petals import Petals -from swarms.models.openai import OpenAI +from swarms.models.openai import OpenAIChat \ No newline at end of file diff --git a/swarms/models/openai.py b/swarms/models/openai.py index 627a2eb4..9d324882 100644 --- a/swarms/models/openai.py +++ b/swarms/models/openai.py @@ -1,27 +1,41 @@ -#kye -#aug 8, 11:51 -import warnings +from __future__ import annotations + import logging import sys +import warnings from typing import ( + AbstractSet, Any, + AsyncIterator, Collection, Dict, - Field, + Iterator, List, Literal, + Mapping, Optional, Tuple, Union, - AbstractSet ) -import openai -import tiktoken -import os +from langchain.callbacks.manager import ( + AsyncCallbackManagerForLLMRun, + CallbackManagerForLLMRun, +) +from langchain.pydantic_v1 import Field, root_validator +from langchain.schema import Generation, LLMResult +from langchain.schema.output import GenerationChunk +from langchain.utils import get_from_dict_or_env + +logger = logging.getLogger(__name__) + +import os def get_from_dict_or_env( - data: Dict[str, Any], key: str, env_key: str, default: Optional[str] = None + data: Dict[str, Any], + key: str, + env_key: str, + default: Optional[str] = None ) -> str: """Get a value from a dictionary or an environment variable.""" if key in data and data[key]: @@ -46,7 +60,7 @@ def get_from_env(key: str, env_key: str, default: Optional[str] = None) -> str: -class OpenAIChat(BaseLLM): +class OpenAIChat: """OpenAI Chat large language models. To use, you should have the ``openai`` python package installed, and the