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

Move provider definitions to separate package #80

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions gptcli/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from attr import dataclass
import platform
from typing import Any, Dict, Iterator, Optional, TypedDict, List
from gptcli.cohere import CohereCompletionProvider

from gptcli.completion import (
CompletionEvent,
CompletionProvider,
ModelOverrides,
Message,
)
from gptcli.llama import LLaMACompletionProvider
from gptcli.openai import OpenAICompletionProvider
from gptcli.anthropic import AnthropicCompletionProvider
from gptcli.providers.llama import LLaMACompletionProvider
from gptcli.providers.openai import OpenAICompletionProvider
from gptcli.providers.anthropic import AnthropicCompletionProvider
from gptcli.providers.cohere import CohereCompletionProvider


class AssistantConfig(TypedDict, total=False):
Expand Down
2 changes: 1 addition & 1 deletion gptcli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import yaml

from gptcli.assistant import AssistantConfig
from gptcli.llama import LLaMAModelConfig
from gptcli.providers.llama import LLaMAModelConfig


CONFIG_FILE_PATHS = [
Expand Down
10 changes: 5 additions & 5 deletions gptcli/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import sys
import logging
import datetime
import gptcli.anthropic
import gptcli.cohere
import gptcli.providers.anthropic
import gptcli.providers.cohere
from gptcli.assistant import (
Assistant,
DEFAULT_ASSISTANTS,
Expand All @@ -32,7 +32,7 @@
choose_config_file,
read_yaml_config,
)
from gptcli.llama import init_llama_models
from gptcli.providers.llama import init_llama_models
from gptcli.logging import LoggingChatListener
from gptcli.cost import PriceChatListener
from gptcli.session import ChatSession
Expand Down Expand Up @@ -184,10 +184,10 @@ def main():
openai.api_key = config.openai_api_key

if config.anthropic_api_key:
gptcli.anthropic.api_key = config.anthropic_api_key
gptcli.providers.anthropic.api_key = config.anthropic_api_key

if config.cohere_api_key:
gptcli.cohere.api_key = config.cohere_api_key
gptcli.providers.cohere.api_key = config.cohere_api_key

if config.llama_models is not None:
init_llama_models(config.llama_models)
Expand Down
Empty file added gptcli/providers/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions gptcli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def simple_response(assistant: Assistant, prompt: str, stream: bool) -> None:
result = ""
try:
for response in response_iter:
result += response
sys.stdout.write(response)
if response.type == "message_delta":
result += response.text
sys.stdout.write(response.text)
except KeyboardInterrupt:
pass
finally:
Expand All @@ -29,6 +30,8 @@ def execute(assistant: Assistant, prompt: str) -> None:
logging.info("User: %s", prompt)
response_iter = assistant.complete_chat(messages, stream=False)
result = next(response_iter)
assert result.type == "message_delta"
result = result.text
logging.info("Assistant: %s", result)

with tempfile.NamedTemporaryFile(mode="w", prefix="gptcli-", delete=False) as f:
Expand Down
Loading