Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for anthropic, cohere, replicate and azure #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions minichain/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from dataclasses import dataclass
from types import TracebackType
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple

import litellm
from litellm import completion, embedding
from eliot import start_action, to_file

if TYPE_CHECKING:
Expand Down Expand Up @@ -190,29 +191,13 @@ def run(self, request: str) -> str:
import manifest

chat = {"gpt-4", "gpt-3.5-turbo"}
manifest = manifest.Manifest(
client_name="openaichat" if self.model in chat else "openai",
max_tokens=self.options["max_tokens"],
cache_name="sqlite",
cache_connection=f"{MinichainContext.name}",
)
messages=[{"role": "user", "content": request}]
ans = completion(model=self.model, messages=messages, stop=self.stop)

ans = manifest.run(
request,
stop_sequences=self.stop,
)
return str(ans)
return ans["choices"][0]["messages"]["content"]

def run_stream(self, prompt: str) -> Iterator[str]:
import openai

self.api_key = os.environ.get("OPENAI_API_KEY")
assert (
self.api_key
), "Need an OPENAI_API_KEY. Get one here https://openai.com/api/"
openai.api_key = self.api_key

for chunk in openai.ChatCompletion.create(
for chunk in completion(
model=self.model,
messages=[{"role": "user", "content": prompt}],
stream=True,
Expand All @@ -233,14 +218,13 @@ def __init__(self, model: str = "text-embedding-ada-002", **kwargs: Any) -> None
def run(self, request: str) -> str:
import openai

self.api_key = os.environ.get("OPENAI_API_KEY")
litellm.openai_key = os.environ.get("OPENAI_API_KEY")
assert (
self.api_key
litellm.openai_key
), "Need an OPENAI_API_KEY. Get one here https://openai.com/api/"
openai.api_key = self.api_key

ans = openai.Embedding.create(
engine=self.model,
ans = embedding(
model=self.model,
input=request,
)
return ans["data"][0]["embedding"] # type: ignore
Expand Down