1.1.0 • Published 6 months ago
deepseek-react v1.1.0
deepseek-react
🚀 React Wrapper for DeepSeek AI API
deepseek-react
is a lightweight React package that provides seamless integration with DeepSeek AI, allowing developers to interact with the DeepSeek API effortlessly.
📦 Installation
To install the package, run:
npm install deepseek-react
Or with Yarn:
yarn add deepseek-react
🔧 Setup & Usage
2️⃣ Using in a React Project
For React projects, wrap your app with DeepSeekProvider
to manage the API key and configuration globally.
import React from "react";
import { DeepSeekProvider, useDeepSeekAPI } from "deepseek-react";
const DeepSeekComponent = () => {
const { data, loading, error, callDeepSeek } = useDeepSeekAPI();
return (
<div>
<button onClick={() => callDeepSeek("chatCompletion", { messages: [{ role: "user", content: "Tell me a joke" }] })}>
Ask DeepSeek AI
</button>
{loading && <p>Loading...</p>}
{error && <p>Error: {error}</p>}
{data && <p>Response: {data.choices[0].message.content}</p>}
</div>
);
};
const App = () => (
<DeepSeekProvider apiKey="your-api-key-here" model="deepseek-chat-v2" baseURL="https://api.deepseek.com">
<DeepSeekComponent />
</DeepSeekProvider>
);
export default App;
📌 API Methods
chatCompletion(messages, model?)
Generate responses using DeepSeek AI’s chat model.
const response = await deepseek.chatCompletion([
{ role: "user", content: "What is AI?" }
], "deepseek-chat-v2");
🛠 Configuration
You can configure API settings inside DeepSeekProvider
:
<DeepSeekProvider apiKey="your-api-key" model="deepseek-chat-v2" baseURL="https://api.deepseek.com">
<YourApp />
</DeepSeekProvider>
🌎 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
📄 License
This project is licensed under the MIT License.