Skip to content

Commit

Permalink
Merge pull request #291 from edenai/SD2-948-fix-all-edenai-apis-faili…
Browse files Browse the repository at this point in the history
…ng-tests

SD2-948-fix-all-edenai-apis-failing-tests
  • Loading branch information
juandavidcruzgomez authored Dec 16, 2024
2 parents f6b698f + 141ceb4 commit 03304f4
Show file tree
Hide file tree
Showing 23 changed files with 297 additions and 578 deletions.
1 change: 1 addition & 0 deletions edenai_apis/apis/amazon/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
r"An error occurred \(ValidationException\) when calling the \w+ operation: 1 validation error detected: Value '.*' at 'image\.bytes' failed to satisfy constraint: Member must have length less than or equal to \d+",
],
ProviderInvalidInputAudioDurationError: [
r"The input media file length is too small. Minimum audio duration is 0.500000 seconds. Check the length of the file and try your request again",
r"The input media file length is too small\. Minimum audio duration is 0\.500000 milliseconds\. Check the length of the file and try your request again\.",
r"Your audio file must have a speech segment long enough in duration to perform automatic language identification\. Provide an audio file with someone speaking for a longer period of time and try your request again",
],
Expand Down
12 changes: 8 additions & 4 deletions edenai_apis/apis/anthropic/outputs/text/chat_output.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"original_response": {
"id": "msg_01VyBzoaKXotthEsFdsUqhxZ",
"id": "msg_bdrk_013mcN9k1Bh8uH8TpV6XAjzM",
"type": "message",
"role": "assistant",
"model": "claude-3-sonnet-20240229",
"content": [
{
"type": "text",
"text": "barack hussein obama, democratic party, african-american, united states, illinois, senator"
}
],
"model": "claude-3-sonnet-28k-20240229",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
Expand All @@ -23,11 +23,15 @@
"message": [
{
"role": "user",
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004."
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004.",
"tools": null,
"tool_calls": null
},
{
"role": "assistant",
"message": "barack hussein obama, democratic party, african-american, united states, illinois, senator"
"message": "barack hussein obama, democratic party, african-american, united states, illinois, senator",
"tools": null,
"tool_calls": null
}
]
}
Expand Down
341 changes: 35 additions & 306 deletions edenai_apis/apis/cohere/outputs/text/chat_output.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion edenai_apis/apis/google/google_video_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@
)
from edenai_apis.apis.amazon.helpers import check_webhook_result
from edenai_apis.features.video.video_interface import VideoInterface
from edenai_apis.utils.exception import ProviderException
from edenai_apis.utils.exception import (
ProviderException,
AsyncJobException,
AsyncJobExceptionReason,
)
from edenai_apis.utils.types import (
AsyncBaseResponseType,
AsyncLaunchJobResponseType,
Expand Down Expand Up @@ -860,6 +864,10 @@ def video__question_answer_async__get_job_result(
api_key = self.api_settings.get("genai_api_key")
url = f"https://generativelanguage.googleapis.com/v1beta/files/{provider_job_id}?key={api_key}"
response = requests.get(url=url)
if response.status_code == 403:
raise AsyncJobException(
reason=AsyncJobExceptionReason.DEPRECATED_JOB_ID, code=403
)
if response.status_code != 200:
raise ProviderException(message=response.text, code=response.status_code)
try:
Expand Down
97 changes: 24 additions & 73 deletions edenai_apis/apis/google/outputs/text/chat_output.json
Original file line number Diff line number Diff line change
@@ -1,89 +1,40 @@
{
"original_response": {
"predictions": [
"candidates": [
{
"candidates": [
{
"author": "bot",
"content": " barack hussein obama, united states, democratic party, african-american, illinois, u.s. senator"
}
],
"safetyAttributes": [
{
"scores": [
0.1,
0.2,
1,
0.1
],
"safetyRatings": [
{
"probabilityScore": 0.1,
"severity": "NEGLIGIBLE",
"category": "Dangerous Content",
"severityScore": 0.1
},
{
"category": "Harassment",
"severityScore": 0.1,
"severity": "NEGLIGIBLE",
"probabilityScore": 0.2
},
{
"severity": "NEGLIGIBLE",
"category": "Hate Speech",
"severityScore": 0.2,
"probabilityScore": 0.1
},
{
"severityScore": 0,
"probabilityScore": 0.1,
"severity": "NEGLIGIBLE",
"category": "Sexually Explicit"
}
],
"categories": [
"Derogatory",
"Insult",
"Politics",
"Sexual"
],
"blocked": false
}
],
"groundingMetadata": [
{}
],
"citationMetadata": [
{
"citations": []
}
]
}
],
"metadata": {
"tokenMetadata": {
"outputTokenCount": {
"totalBillableCharacters": 85,
"totalTokens": 25
"content": {
"parts": [
{
"text": "barack obama, united states\n"
}
],
"role": "model"
},
"inputTokenCount": {
"totalBillableCharacters": 836,
"totalTokens": 216
}
"finishReason": "STOP",
"avgLogprobs": -0.2852514088153839
}
}
],
"usageMetadata": {
"promptTokenCount": 220,
"candidatesTokenCount": 8,
"totalTokenCount": 228
},
"modelVersion": "gemini-1.5-pro-002"
},
"standardized_response": {
"generated_text": " barack hussein obama, united states, democratic party, african-american, illinois, u.s. senator",
"generated_text": "barack obama, united states\n",
"message": [
{
"role": "user",
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004."
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004.",
"tools": null,
"tool_calls": null
},
{
"role": "assistant",
"message": " barack hussein obama, united states, democratic party, african-american, illinois, u.s. senator"
"message": "barack obama, united states\n",
"tools": null,
"tool_calls": null
}
]
}
Expand Down
16 changes: 10 additions & 6 deletions edenai_apis/apis/meta/outputs/text/chat_output.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{
"original_response": {
"generation": "barack obama, united states, democratic party, illinois",
"generation": "Barack Obama, United States, Democratic Party, Illinois",
"prompt_token_count": 228,
"generation_token_count": 14,
"generation_token_count": 12,
"stop_reason": "stop",
"usage": {
"total_tokens": 242
"total_tokens": 240
}
},
"standardized_response": {
"generated_text": "barack obama, united states, democratic party, illinois",
"generated_text": "Barack Obama, United States, Democratic Party, Illinois",
"message": [
{
"role": "user",
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004."
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004.",
"tools": null,
"tool_calls": null
},
{
"role": "assistant",
"message": "barack obama, united states, democratic party, illinois"
"message": "Barack Obama, United States, Democratic Party, Illinois",
"tools": null,
"tool_calls": null
}
]
}
Expand Down
25 changes: 15 additions & 10 deletions edenai_apis/apis/mistral/outputs/text/chat_output.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
{
"original_response": {
"id": "7787fe11a93848aea82d781ac99a8bb3",
"id": "20b4f926a5874c039f31acf293498613",
"object": "chat.completion",
"created": 1704987671,
"model": "mistral-small",
"created": 1733932539,
"model": "mistral-large-latest",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "barack, hussein, obama, president, united, states, democratic, party, illinois, senator\n\n(Note: I've included \"president\" as a keyword even though it's part of the sentence \"president of the United States\" because it is a key role and title associated with Barack Obama.)"
"tool_calls": null,
"content": "Obama\nAmerican\npresident\nUnited States\nDemocratic\nAfrican-American\nsenator\nIllinois"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 271,
"total_tokens": 343,
"completion_tokens": 72
"prompt_tokens": 260,
"total_tokens": 285,
"completion_tokens": 25
}
},
"standardized_response": {
"generated_text": "barack, hussein, obama, president, united, states, democratic, party, illinois, senator\n\n(Note: I've included \"president\" as a keyword even though it's part of the sentence \"president of the United States\" because it is a key role and title associated with Barack Obama.)",
"generated_text": "Obama\nAmerican\npresident\nUnited States\nDemocratic\nAfrican-American\nsenator\nIllinois",
"message": [
{
"role": "user",
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004."
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004.",
"tools": null,
"tool_calls": null
},
{
"role": "assistant",
"message": "barack, hussein, obama, president, united, states, democratic, party, illinois, senator\n\n(Note: I've included \"president\" as a keyword even though it's part of the sentence \"president of the United States\" because it is a key role and title associated with Barack Obama.)"
"message": "Obama\nAmerican\npresident\nUnited States\nDemocratic\nAfrican-American\nsenator\nIllinois",
"tools": null,
"tool_calls": []
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion edenai_apis/apis/openai/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
"models": [
"dall-e-2"
],
"default_model": "dall-e-2"
"default_model": "dall-e-3"
},
"version": "v1.0"
},
Expand Down
13 changes: 6 additions & 7 deletions edenai_apis/apis/openai/openai_image_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ def image__question_answer(
def image__variation(
self,
file: str,
prompt: Optional[str] = "",
prompt: Optional[str],
num_images: Optional[int] = 1,
resolution: Literal["256x256", "512x512", "1024x1024"] = "512x512",
temperature: Optional[int] = 0.3,
temperature: Optional[float] = 0.3,
model: Optional[str] = None,
file_url: str = "",
) -> ResponseType[VariationDataClass]:
try:
with open(file, "rb") as file_:
response = self.client.images.generate(
response = self.client.images.create_variation(
image=file_,
n=num_images,
model=model,
Expand All @@ -165,9 +165,8 @@ def image__variation(

original_response = response
generations: Sequence[VariationImageDataClass] = []
for generated_image in original_response.get("data"):
image_b64 = generated_image.get("b64_json")

for generated_image in original_response.data:
image_b64 = generated_image.b64_json
image_data = image_b64.encode()
image_content = BytesIO(base64.b64decode(image_data))
resource_url = upload_file_bytes_to_s3(image_content, ".png", USER_PROCESS)
Expand All @@ -178,7 +177,7 @@ def image__variation(
)

return ResponseType[VariationDataClass](
original_response=original_response,
original_response=original_response.to_dict(),
standardized_response=VariationDataClass(items=generations),
)

Expand Down
56 changes: 35 additions & 21 deletions edenai_apis/apis/openai/outputs/text/chat_output.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
{
"original_response": {
"id": "chatcmpl-8KS3Mz2wmYGqUcfncF0ymjAUxozUH",
"object": "chat.completion",
"created": 1699885088,
"model": "gpt-4-1106-vision-preview",
"usage": {
"prompt_tokens": 222,
"completion_tokens": 25,
"total_tokens": 247
},
"id": "chatcmpl-AdJAXPB9SFyLEy1bUbzLo2fHTFM9T",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"role": "assistant",
"content": "Barack Hussein Obama, American, politician, president, United States, Democratic Party, African-American, senator, Illinois, state"
},
"finish_details": {
"type": "stop",
"stop": "<|fim_suffix|>"
},
"index": 0
"content": "Barack Hussein Obama, American, politician, 44th president, United States, 2009, 2017, Democratic Party, African-American, U.S. senator, Illinois, 2005, 2008, state senator, 1997, 2004",
"refusal": null,
"role": "assistant"
}
}
]
],
"created": 1733931841,
"model": "gpt-3.5-turbo-0125",
"object": "chat.completion",
"system_fingerprint": null,
"usage": {
"completion_tokens": 56,
"prompt_tokens": 222,
"total_tokens": 278,
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
}
}
},
"standardized_response": {
"generated_text": "Barack Hussein Obama, American, politician, president, United States, Democratic Party, African-American, senator, Illinois, state",
"generated_text": "Barack Hussein Obama, American, politician, 44th president, United States, 2009, 2017, Democratic Party, African-American, U.S. senator, Illinois, 2005, 2008, state senator, 1997, 2004",
"message": [
{
"role": "user",
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004."
"message": "Barack Hussein Obama is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, Obama was the first African-American president of the United States. He previously served as a U.S. senator from Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004.",
"tools": null,
"tool_calls": null
},
{
"role": "assistant",
"message": "Barack Hussein Obama, American, politician, president, United States, Democratic Party, African-American, senator, Illinois, state"
"message": "Barack Hussein Obama, American, politician, 44th president, United States, 2009, 2017, Democratic Party, African-American, U.S. senator, Illinois, 2005, 2008, state senator, 1997, 2004",
"tools": null,
"tool_calls": []
}
]
}
Expand Down
Loading

0 comments on commit 03304f4

Please sign in to comment.