openai class and error cleanups

Former-commit-id: c3c9d18cfd
group-chat
Kye 1 year ago
parent 82ffe359d6
commit 6129828509

@ -2,7 +2,7 @@ from swarms import Worker
node = Worker(
openai_api_key="",
openai_api_key="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",
ai_name="Optimus Prime",
)

@ -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

@ -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

@ -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

Loading…
Cancel
Save