agentops
agentops copied to clipboard
[Bug]: Session logs are not showing pricing when completions.create from Anthropic is used.
Contact Details
No response
📦 Package Version
0.3.26
🎞️ Framework Version
No response
🔎 Describe the Bug
Was testing completions.create from Anthropic, and it seems like it's not tracking cost. Reference script:
import agentops
from anthropic import Anthropic
agentops.init(
api_key='<AGENTOPS_KEY>',
default_tags=['anthropic']
)
client = Anthropic(api_key='<ANTHROPIC_KEY>')
models = ["claude-2"]
def get_ai_response(model_name):
response = client.completions.create(
model=model_name,
prompt="\n\nHuman: Write a haiku about AI and humans working together\n\nAssistant:",
max_tokens_to_sample=100
)
return response.completion
for model in models:
print(f"Response from {model}:")
try:
ai_response = get_ai_response(model)
print(ai_response)
except Exception as e:
print(f"Error with model {model}: {e}")
print("-" * 50)
agentops.end_session('Success')
🤝 Contribution
- [ ] Yes, I'd be happy to submit a pull request with these changes.
- [ ] I need some guidance on how to contribute.
- [x] I'd prefer the AgentOps team to handle this update.
From the docstring in the Completions.create method located in the anthropic-idk-python repository:
"""[Legacy] Create a Text Completion.
The Text Completions API is a legacy API.
We recommend using the
[Messages API](https://docs.anthropic.com/en/api/messages) going forward.
Future models and features will not be compatible with Text Completions. See our
[migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages)
for guidance in migrating from Text Completions to Messages."""
This is already deprecated along with the Claude-2 model. Thus we don't instrument this method in our code and this is expected.
Noted