This example demonstrates how to use GenSX with Anthropic to create various types of chat completions and streaming responses. The example includes multiple workflows showcasing different capabilities like basic chat and streaming responses.
The example consists of two main workflows:
BasicCompletion: Simple chat completion without any toolsStreamingCompletion: Streaming chat completion
-
Log in to GenSX (if you haven't already):
npx gensx login
-
Install dependencies:
pnpm install
-
Set up your environment variables:
export ANTHROPIC_API_KEY=your_api_key_here
To run the workflow in GenSX Cloud:
-
Deploy your workflow:
pnpm run deploy
-
Run any of the available workflows:
gensx run BasicCompletion --input '{"prompt": "Write a poem about a cat"}' gensx run StreamingCompletion --input '{"prompt": "Tell me a story"}'
Once deployed, you can go to the GenSX console to see your workflows, test them, analyze traces, and get code snippets.
You can run any of the workflows directly using the command line:
# Basic chat
pnpm dev "basic" "Write a poem about a cat"
# Streaming chat
pnpm dev "stream" "Tell me a short story"You can also test the workflow through a local API server:
pnpm startThis will start a local API server and you can call the workflow APIs via curl or any HTTP client:
# Basic chat
curl -X POST http://localhost:1337/workflows/BasicCompletion \
-H "Content-Type: application/json" \
-d '{
"prompt": "Write a poem about a cat"
}'
# Streaming chat
curl -X POST http://localhost:1337/workflows/StreamingCompletion \
-H "Content-Type: application/json" \
-d '{
"prompt": "Tell me a story"
}'A swagger UI will also be available at http://localhost:1337/swagger-ui to view the API details and test the workflow.