-
Notifications
You must be signed in to change notification settings - Fork 75
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
[python] Claude Model Parser #1039
Conversation
757f437
to
c0e248d
Compare
efab7cb
to
933409a
Compare
python/src/aiconfig/Config.py
Outdated
@@ -53,6 +54,7 @@ | |||
DefaultAnyscaleEndpointParser("AnyscaleEndpoint") | |||
) | |||
ModelParserRegistry.register_model_parser(GeminiModelParser("gemini-pro"), ["gemini-pro"]) | |||
ModelParserRegistry.register_model_parser(ClaudeBedrockModelParser(), ["Claude"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to figure out model vs model provider but for now just registering under "Claude" as well
# See https://docs.anthropic.com/claude/docs/introduction-to-prompt-design#human--assistant-formatting | ||
completion_data[ | ||
"prompt" | ||
] = f"{HUMAN_PROMPT} {resolved_prompt}{AI_PROMPT}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if its the best idea to manipulate the prompt inside the model parser
|
||
completion_data["stream"] = stream | ||
|
||
response = self.client.completions.create(**completion_data) # type: ignore (pyright doesn't understand response object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API call will throw If aws credentials are not set. I removed mine locally and tested this manually.
933409a
to
9a53aa4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, big ups
# completion parameters to be used for Claude's Text completion api | ||
# prompt handled separately | ||
# streaming handled separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add uri for easy reference
# prompt handled separately | ||
# streaming handled separately. | ||
supported_keys = { | ||
"max_tokens_to_sample", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note w. Ankush offline: required completion param, we should set default so people don't have to (if not defined in config)
""" | ||
return ExecuteResult( | ||
output_type="execute_result", | ||
data=response.completion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add link to confirm this is a text-based output only
output_type="execute_result", | ||
data=response.completion, | ||
execution_count=0, | ||
metadata=response.model_dump(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wow, pydantic nice thanks Anthropic
for iteration in response: | ||
new_text = iteration.completion | ||
|
||
# Reduce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove because "reduce" typically has other connotation to it
options (InferenceOptions): The inference options. Used to determine the stream callback. | ||
""" | ||
accumulated_message = "" | ||
output = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this always gets overridden so delete
# Client will be set in the run method. This is to avoid having to set the api key in the constructor | ||
self.client = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Create an issue, mention as an issue because this MP is a little weird having 2 potential sources of API KEYS:
aiconfig/extensions/Gemini/python/src/aiconfig_extension_gemini/Gemini.py
Lines 116 to 122 in c838856
# Note: we don't need to explicitly set the key as long as this is set | |
# as an env var genai.configure() will pick up the env var | |
# `GOOGLE_API_KEY`, it's just that we prefer not to call | |
# `get_api_key_from_environment` multiple times if we don't need to | |
self.api_key = get_api_key_from_environment( | |
"GOOGLE_API_KEY", required=False | |
).unwrap() |
This will def come up with the SDK rewrites for MPs
if options is not None and options.stream is not None: | ||
stream = options.stream | ||
elif "stream" in completion_data: | ||
stream = completion_data["stream"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice this is cleaner than the other implementations we have
else: | ||
output = construct_output(response) # type: ignore | ||
|
||
# rewrite or extend list of outputs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea because this is a chat based one right? Hmmmm, let's do demo you and I today. For now unblocking and we can fix forward based on our desired behaviour
# Claude outputs should only ever be string | ||
# format so shouldn't get here, but just being safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I'm talking about
Model Parser for Claude on AWS Bedrock Claude on Bedrock can be called with the - `anthropic_bedrock` python library - AWS' `Boto3` Library - Chose to use the `anthropic_bedrock` library because it has good abstractions and type hints Claude on Bedrock only supports Text Completions, turn style [prompts are not supported](https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock#:~:text=Messages%20in%20Amazon%20Bedrock) - Added Claude model parser as a core parser. - added dependency on `anthropic_bedrock` ## Testplan using prompt schema from diff ontop https://github.com/lastmile-ai/aiconfig/assets/141073967/29c1faa7-7d13-412f-8606-9ad556eb1c52
9a53aa4
to
94bb0d8
Compare
|
[editor] Claude Bedrock Prompt Schema ## Testplan https://github.com/lastmile-ai/aiconfig/assets/141073967/29c1faa7-7d13-412f-8606-9ad556eb1c52 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1050). * __->__ #1050 * #1039
[python] Claude Model Parser
Model Parser for Claude on AWS Bedrock
Claude on Bedrock can be called with the
anthropic_bedrock
python libraryBoto3
Libraryanthropic_bedrock
library because it has good abstractions and type hintsClaude on Bedrock only supports Text Completions, turn style prompts are not supported
anthropic_bedrock
Testplan
using prompt schema from diff ontop
claude.testplan.mov
Stack created with Sapling. Best reviewed with ReviewStack.