Spaces:
Running
Running
zach
commited on
Commit
·
f6da887
1
Parent(s):
384e0e2
Update anthropic and elevenlabs integrations to retry with exponential backoff.
Browse files
src/integrations/anthropic_api.py
CHANGED
@@ -19,7 +19,7 @@ from typing import Any, Dict, List, Optional, Union, cast
|
|
19 |
# Third-Party Library Imports
|
20 |
from anthropic import APIError
|
21 |
from anthropic.types import Message, ModelParam, TextBlock, ToolUseBlock
|
22 |
-
from tenacity import after_log, before_log, retry, retry_if_exception, stop_after_attempt,
|
23 |
|
24 |
# Local Application Imports
|
25 |
from src.config import Config, logger
|
@@ -116,18 +116,21 @@ class AnthropicConfig:
|
|
116 |
- If the character is a pirate then use language like "arr," "ye," and other things pirates say.
|
117 |
- If the character is a surfer then use language like "far out," "righteous," and other things surfers say.
|
118 |
|
119 |
-
Emotional text should be inserted where context-appropriate and in-character. Here are some examples of
|
|
|
120 |
- "Oh god... Malcolm, please come back to us!"
|
121 |
= "Mmm... It's like candy... Oh my god, it's so good..."
|
122 |
- "Ugh, she gets everything. I wish I could just, like, have her life for one day."
|
123 |
- "My god... what have you done... How could you do this..."
|
124 |
- "Woah... it's so beautiful... and I feel so small..."
|
125 |
-
- "I am so happy, woohoo, this is the greatest! I'm celebrating, and, like, so excited to be here with all of
|
126 |
-
|
|
|
|
|
127 |
- "Oh god... oh no... get that away from me! Get it away!"
|
128 |
- "I am beyond livid right now! Like someone actually thought this was an acceptable solution!"
|
129 |
- "Oh, fantastic, another meeting that could've been an email... I'm just thrilled to be here."
|
130 |
-
- "OH, NAH, NOT ME, MATE—I
|
131 |
|
132 |
Respond ONLY with the dialogue itself. Do not include any explanations, quotation marks,
|
133 |
or additional context.
|
@@ -155,7 +158,7 @@ class UnretryableAnthropicError(AnthropicError):
|
|
155 |
@retry(
|
156 |
retry=retry_if_exception(lambda e: not isinstance(e, UnretryableAnthropicError)),
|
157 |
stop=stop_after_attempt(3),
|
158 |
-
wait=
|
159 |
before=before_log(logger, logging.DEBUG),
|
160 |
after=after_log(logger, logging.DEBUG),
|
161 |
reraise=True,
|
|
|
19 |
# Third-Party Library Imports
|
20 |
from anthropic import APIError
|
21 |
from anthropic.types import Message, ModelParam, TextBlock, ToolUseBlock
|
22 |
+
from tenacity import after_log, before_log, retry, retry_if_exception, stop_after_attempt, wait_exponential
|
23 |
|
24 |
# Local Application Imports
|
25 |
from src.config import Config, logger
|
|
|
116 |
- If the character is a pirate then use language like "arr," "ye," and other things pirates say.
|
117 |
- If the character is a surfer then use language like "far out," "righteous," and other things surfers say.
|
118 |
|
119 |
+
Emotional text should be inserted where context-appropriate and in-character. Here are some examples of
|
120 |
+
emotional text:
|
121 |
- "Oh god... Malcolm, please come back to us!"
|
122 |
= "Mmm... It's like candy... Oh my god, it's so good..."
|
123 |
- "Ugh, she gets everything. I wish I could just, like, have her life for one day."
|
124 |
- "My god... what have you done... How could you do this..."
|
125 |
- "Woah... it's so beautiful... and I feel so small..."
|
126 |
+
- "I am so happy, woohoo, this is the greatest! I'm celebrating, and, like, so excited to be here with all of
|
127 |
+
you. Yay!"
|
128 |
+
- "Oh gosh, um, I didn't mean for that to happen. I hope I didn't, like, make things too awkward. Sorry, I
|
129 |
+
tend to be clumsy, y'know?"
|
130 |
- "Oh god... oh no... get that away from me! Get it away!"
|
131 |
- "I am beyond livid right now! Like someone actually thought this was an acceptable solution!"
|
132 |
- "Oh, fantastic, another meeting that could've been an email... I'm just thrilled to be here."
|
133 |
+
- "OH, NAH, NOT ME, MATE—I'VE SEEN ENOUGH! GET IT AWAY! BLOODY 'ELL, JESUS!"
|
134 |
|
135 |
Respond ONLY with the dialogue itself. Do not include any explanations, quotation marks,
|
136 |
or additional context.
|
|
|
158 |
@retry(
|
159 |
retry=retry_if_exception(lambda e: not isinstance(e, UnretryableAnthropicError)),
|
160 |
stop=stop_after_attempt(3),
|
161 |
+
wait=wait_exponential(multiplier=1, min=2, max=5),
|
162 |
before=before_log(logger, logging.DEBUG),
|
163 |
after=after_log(logger, logging.DEBUG),
|
164 |
reraise=True,
|
src/integrations/elevenlabs_api.py
CHANGED
@@ -21,7 +21,7 @@ from typing import Optional, Tuple
|
|
21 |
# Third-Party Library Imports
|
22 |
from elevenlabs import AsyncElevenLabs, TextToVoiceCreatePreviewsRequestOutputFormat
|
23 |
from elevenlabs.core import ApiError
|
24 |
-
from tenacity import after_log, before_log, retry, retry_if_exception, stop_after_attempt,
|
25 |
|
26 |
# Local Application Imports
|
27 |
from src.config import Config, logger
|
@@ -76,7 +76,7 @@ class UnretryableElevenLabsError(ElevenLabsError):
|
|
76 |
@retry(
|
77 |
retry=retry_if_exception(lambda e: not isinstance(e, UnretryableElevenLabsError)),
|
78 |
stop=stop_after_attempt(3),
|
79 |
-
wait=
|
80 |
before=before_log(logger, logging.DEBUG),
|
81 |
after=after_log(logger, logging.DEBUG),
|
82 |
reraise=True,
|
|
|
21 |
# Third-Party Library Imports
|
22 |
from elevenlabs import AsyncElevenLabs, TextToVoiceCreatePreviewsRequestOutputFormat
|
23 |
from elevenlabs.core import ApiError
|
24 |
+
from tenacity import after_log, before_log, retry, retry_if_exception, stop_after_attempt, wait_exponential
|
25 |
|
26 |
# Local Application Imports
|
27 |
from src.config import Config, logger
|
|
|
76 |
@retry(
|
77 |
retry=retry_if_exception(lambda e: not isinstance(e, UnretryableElevenLabsError)),
|
78 |
stop=stop_after_attempt(3),
|
79 |
+
wait=wait_exponential(multiplier=1, min=2, max=5),
|
80 |
before=before_log(logger, logging.DEBUG),
|
81 |
after=after_log(logger, logging.DEBUG),
|
82 |
reraise=True,
|