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( node = Worker(
openai_api_key="", openai_api_key="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",
ai_name="Optimus Prime", ai_name="Optimus Prime",
) )

@ -13,6 +13,6 @@ from swarms.models.anthropic import Anthropic
from swarms.models.huggingface import HuggingFaceLLM from swarms.models.huggingface import HuggingFaceLLM
# from swarms.models.palm import GooglePalm # from swarms.models.palm import GooglePalm
from swarms.models.petals import Petals 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.huggingface import HuggingFaceLLM
# from swarms.models.palm import GooglePalm # from swarms.models.palm import GooglePalm
from swarms.models.petals import Petals from swarms.models.petals import Petals
from swarms.models.openai import OpenAI from swarms.models.openai import OpenAIChat

@ -1,27 +1,41 @@
#kye from __future__ import annotations
#aug 8, 11:51
import warnings
import logging import logging
import sys import sys
import warnings
from typing import ( from typing import (
AbstractSet,
Any, Any,
AsyncIterator,
Collection, Collection,
Dict, Dict,
Field, Iterator,
List, List,
Literal, Literal,
Mapping,
Optional, Optional,
Tuple, Tuple,
Union, Union,
AbstractSet
) )
import openai from langchain.callbacks.manager import (
import tiktoken AsyncCallbackManagerForLLMRun,
import os 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( 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: ) -> str:
"""Get a value from a dictionary or an environment variable.""" """Get a value from a dictionary or an environment variable."""
if key in data and data[key]: 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. """OpenAI Chat large language models.
To use, you should have the ``openai`` python package installed, and the To use, you should have the ``openai`` python package installed, and the

Loading…
Cancel
Save