Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can you provide an example of how to initiate a chat session using DeepSeek R1 and Together.ai


Can you provide an example of how to initiate a chat session using DeepSeek R1 and Together.ai


Initiating a chat session using DeepSeek R1 and Together.ai involves several steps, including setting up an account with Together.ai, obtaining an API key, and integrating it with a platform like Appsmith. Here's a detailed guide on how to do it:

Step 1: Create a Together.ai Account and Obtain an API Key

1. Sign Up: Go to Together.ai and create an account. During the onboarding process, you will be provided with an API key. If you miss this step, you can create a new API key manually.

2. API Key: Ensure you have your API key ready, as it will be used for authentication in the API calls.

Step 2: Set Up Appsmith for Integration

1. Open Appsmith Editor: Log into your Appsmith account and open the editor.

2. Create a New Query: Navigate to the Queries tab and click on the "+" button to create a new query. Select "New Curl Import."

3. Paste the API Request: In the curl import window, paste the following command but do not click import yet:

bash
   curl -X POST "https://api.together.xyz/v1/chat/completions" \
   -H "Authorization: Bearer $TOGETHER_API_KEY" \
   -H "Content-Type: application/json" \
   -d '{
     "model": "deepseek-ai/DeepSeek-R1",
     "messages": [
       {
         "role": "user",
         "content": "Hello, how are you?"
       }
     ],
     "max_tokens": null,
     "temperature": 0.7,
     "top_p": 0.7,
     "top_k": 50,
     "repetition_penalty": 1,
     "stop": [""],
     "stream": false
   }'
   

4. Replace API Key: Replace `$TOGETHER_API_KEY` with your actual API key from Together.ai.

5. Import the Query: Click "Import" to create the query in Appsmith.

6. Rename the Query: Rename the query to something like "sendMessage."

7. Adjust Timeout: Click on the gear next to the run button and increase the timeout to 60 seconds.

Step 3: Run the Query and Set Up the Chat App

1. Run the Query: Click "Run" to execute the query and receive a response from the Together.ai API using the DeepSeek R1 model.

2. Save API Key Securely: Move the API key to the Authentication section to store it securely.

3. Build the Chat UI: Drag in a Text widget, Input widget, and Button widget to create a simple chat interface.

4. Configure Widgets:
- Text Widget: Display the response from the API using ``.
- Input Widget: Allow users to input their messages.
- Button Widget: Trigger the API call when clicked.

5. Test the Chat App: Enter a message in the input field and click the button to send it to the DeepSeek R1 model via Together.ai. The response will be displayed in the text widget.

By following these steps, you can initiate a chat session using DeepSeek R1 and Together.ai, leveraging the reasoning capabilities of the DeepSeek model within a user-friendly chat app interface.

Citations:
[1] https://thinhdanggroup.github.io/blog-on-chat-deepseek-r1-api/
[2] https://community.appsmith.com/content/guide/building-chat-app-deepseek-r1-and-togetherai-under-5-minutes
[3] https://www.datacamp.com/tutorial/deepseek-api
[4] https://www.youtube.com/watch?v=flD7gJSY9z4
[5] https://thinktank.ottomator.ai/t/together-ai-offering-100-free-credits-and-deepseek-r1/4892
[6] https://learn.microsoft.com/en-us/azure/ai-foundry/model-inference/tutorials/get-started-deepseek-r1?context=%2Fazure%2Fai-foundry%2Fcontext%2Fcontext
[7] https://www.youtube.com/watch?v=3_OoICZYwy4
[8] https://618media.com/en/blog/integrating-deepseek-r1-into-existing-systems-a-guide/