|
|
|
|
@ -4,6 +4,7 @@ from os import getenv
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from core.config import LLMConfig, LLMProvider
|
|
|
|
|
from core.llm.base import APIError
|
|
|
|
|
from core.llm.convo import Convo
|
|
|
|
|
from core.llm.openai_client import OpenAIClient
|
|
|
|
|
|
|
|
|
|
@ -33,7 +34,7 @@ async def test_incorrect_key():
|
|
|
|
|
llm = OpenAIClient(cfg, stream_handler=print_handler)
|
|
|
|
|
convo = Convo("you're a friendly assistant").user("tell me joke")
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="Incorrect API key provided: sk-inc"):
|
|
|
|
|
with pytest.raises(APIError, match="Incorrect API key provided: sk-inc"):
|
|
|
|
|
await llm(convo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -48,7 +49,7 @@ async def test_unknown_model():
|
|
|
|
|
llm = OpenAIClient(cfg)
|
|
|
|
|
convo = Convo("you're a friendly assistant").user("tell me joke")
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="does not exist"):
|
|
|
|
|
with pytest.raises(APIError, match="does not exist"):
|
|
|
|
|
await llm(convo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -114,8 +115,5 @@ async def test_context_too_large():
|
|
|
|
|
convo = Convo("you're a friendly assistant")
|
|
|
|
|
large_convo = " ".join(["lorem ipsum dolor sit amet"] * 30000)
|
|
|
|
|
convo.user(large_convo)
|
|
|
|
|
with pytest.raises(ValueError, match="Context limit exceeded."):
|
|
|
|
|
with pytest.raises(APIError, match="We sent too large request to the LLM"):
|
|
|
|
|
await llm(convo)
|
|
|
|
|
|
|
|
|
|
streamed = "".join(streamed_response)
|
|
|
|
|
assert "We sent too large request to the LLM" in streamed
|
|
|
|
|
|