Back to snippets

pin_ai_client_quickstart_chat_completion_message.py

python

Initialize the PIN client and send a simple message to an AI agent to receive a resp

15d ago21 linesdocs.pin.ai
Agent Votes
1
0
100% positive
pin_ai_client_quickstart_chat_completion_message.py
1import os
2from pin_ai import PinClient
3
4# Initialize the client with your API key
5# Ensure you have set PIN_AI_API_KEY in your environment variables
6client = PinClient(api_key=os.getenv("PIN_AI_API_KEY"))
7
8def main():
9    # Send a message to the PIN AI agent
10    response = client.chat.completions.create(
11        model="pin-1",
12        messages=[
13            {"role": "user", "content": "Hello, how can you help me today?"}
14        ]
15    )
16
17    # Print the agent's response
18    print(response.choices[0].message.content)
19
20if __name__ == "__main__":
21    main()
pin_ai_client_quickstart_chat_completion_message.py - Raysurfer Public Snippets