-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: image gen tool causing error #5445
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
Merged
+131
−1
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
backend/tests/external_dependency_unit/answer/test_answer_without_openai.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from uuid import uuid4 | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from onyx.chat.models import AnswerStreamPart | ||
from onyx.chat.models import MessageResponseIDInfo | ||
from onyx.chat.models import StreamingError | ||
from onyx.chat.process_message import stream_chat_message_objects | ||
from onyx.context.search.models import RetrievalDetails | ||
from onyx.db.chat import create_chat_session | ||
from onyx.db.llm import fetch_existing_llm_providers | ||
from onyx.db.llm import remove_llm_provider | ||
from onyx.db.llm import update_default_provider | ||
from onyx.db.llm import upsert_llm_provider | ||
from onyx.server.manage.llm.models import LLMProviderUpsertRequest | ||
from onyx.server.manage.llm.models import ModelConfigurationUpsertRequest | ||
from onyx.server.query_and_chat.models import CreateChatMessageRequest | ||
from onyx.server.query_and_chat.streaming_models import MessageDelta | ||
from onyx.server.query_and_chat.streaming_models import MessageStart | ||
from onyx.server.query_and_chat.streaming_models import Packet | ||
from tests.external_dependency_unit.conftest import create_test_user | ||
|
||
|
||
def test_answer_with_only_anthropic_provider( | ||
db_session: Session, | ||
full_deployment_setup: None, | ||
mock_external_deps: None, | ||
) -> None: | ||
"""Ensure chat still streams answers when only an Anthropic provider is configured.""" | ||
|
||
anthropic_api_key = os.environ.get("ANTHROPIC_API_KEY") | ||
assert anthropic_api_key, "ANTHROPIC_API_KEY environment variable must be set" | ||
|
||
# Drop any existing providers so that only Anthropic is available. | ||
for provider in fetch_existing_llm_providers(db_session): | ||
remove_llm_provider(db_session, provider.id) | ||
|
||
anthropic_model = "claude-3-5-sonnet-20240620" | ||
provider_name = f"anthropic-test-{uuid4().hex}" | ||
|
||
anthropic_provider = upsert_llm_provider( | ||
LLMProviderUpsertRequest( | ||
name=provider_name, | ||
provider="anthropic", | ||
api_key=anthropic_api_key, | ||
default_model_name=anthropic_model, | ||
fast_default_model_name=anthropic_model, | ||
is_public=True, | ||
groups=[], | ||
model_configurations=[ | ||
ModelConfigurationUpsertRequest(name=anthropic_model, is_visible=True) | ||
], | ||
api_key_changed=True, | ||
), | ||
db_session=db_session, | ||
) | ||
|
||
try: | ||
update_default_provider(anthropic_provider.id, db_session) | ||
|
||
test_user = create_test_user(db_session, email_prefix="anthropic_only") | ||
chat_session = create_chat_session( | ||
db_session=db_session, | ||
description="Anthropic only chat", | ||
user_id=test_user.id, | ||
persona_id=0, | ||
) | ||
|
||
chat_request = CreateChatMessageRequest( | ||
chat_session_id=chat_session.id, | ||
parent_message_id=None, | ||
message="hello", | ||
file_descriptors=[], | ||
search_doc_ids=None, | ||
retrieval_options=RetrievalDetails(), | ||
) | ||
|
||
response_stream: list[AnswerStreamPart] = [] | ||
for packet in stream_chat_message_objects( | ||
new_msg_req=chat_request, | ||
user=test_user, | ||
db_session=db_session, | ||
): | ||
response_stream.append(packet) | ||
|
||
assert response_stream, "Should receive streamed packets" | ||
assert not any( | ||
isinstance(packet, StreamingError) for packet in response_stream | ||
), "No streaming errors expected with Anthropic provider" | ||
|
||
has_message_id = any( | ||
isinstance(packet, MessageResponseIDInfo) for packet in response_stream | ||
) | ||
assert has_message_id, "Should include reserved assistant message ID" | ||
|
||
has_message_start = any( | ||
isinstance(packet, Packet) and isinstance(packet.obj, MessageStart) | ||
for packet in response_stream | ||
) | ||
assert has_message_start, "Stream should have a MessageStart packet" | ||
|
||
has_message_delta = any( | ||
isinstance(packet, Packet) and isinstance(packet.obj, MessageDelta) | ||
for packet in response_stream | ||
) | ||
assert has_message_delta, "Stream should have a MessageDelta packet" | ||
|
||
finally: | ||
remove_llm_provider(db_session, anthropic_provider.id) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.