Comments (2)
@Montana it looks like you're using the completions API, please switch to the messages API. https://github.com/anthropics/anthropic-sdk-python#usage
from anthropic-sdk-python.
Hi @RobertCraigie,
I went back to completion via:
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
try:
response = client.completions.create(
model="claude-2",
max_tokens_to_sample=1000,
prompt=f"{HUMAN_PROMPT} Please correct this Travis CI YAML file:\n\n{yml_content}\n\n{AI_PROMPT}"
)
logging.info("YAML correction successful")
return response.completion.split("Key Points")[0].strip() # montana remember to for loop
except Exception as e:
logging.error(f"Error correcting YAML: {str(e)}")
return f"Error correcting YAML: {str(e)}"
def send_anthropic_prompt(prompt):
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
try:
response = client.completions.create(
model="claude-2",
max_tokens_to_sample=2000,
prompt=f"{HUMAN_PROMPT} Please assist with the following:\n\n{prompt}\n\n{AI_PROMPT}"
)
logging.info("Received response from Anthropic")
return response.completion
except Exception as e:
logging.error(f"Error sending prompt to Anthropic: {str(e)}")
return "I apologize, but I'm currently unable to process your request due to a technical issue. Please try again later or contact support if the problem persists."
It works fine again, not sure what the issue is. API keys were fine. This is was working yesterday - but today I had to change the logic a bit and it worked.
Cheers,
Montana
from anthropic-sdk-python.
Related Issues (20)
- Which Pydantic class to use for streaming messages? HOT 1
- Support String In ToolResultBlock param? 🧌 HOT 3
- Support Tool Choice Type: None
- httpx.PoolTimeout, fixed by disabling HTTP keepalive HOT 5
- Support Parallel Tool Calls = False
- Feature-request: Pydantic validators+serializers to be able to round-trip all supported types HOT 11
- API Requests Within Existing Projects HOT 2
- AnthropicVertex stream chat generation is taking too much time HOT 7
- AnthropicVertex does not expose `with_options` HOT 3
- Error in the vertex AI documentation HOT 2
- Missing token count feature HOT 1
- Vertex "Could not resolve API token from the environment" HOT 9
- Wrong request options in retries HOT 4
- Is there a way to manage Claude Projects in Web UI via the API? HOT 1
- nest_asyncio hangs AsyncAnthropic
- `timeout` parameter doesn't seem to have any effect HOT 1
- Feature request: return the number of failed attempts HOT 2
- Async usage is broken as of 0.29.0 for client.messages.create HOT 3
- Feature request: tool_choice='none' for analysing available tools - but not using them HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anthropic-sdk-python.