logoAnt Design X

DesignDevelopmentComponentsPlayground
  • Ant Design X of React
  • Changelog
    v1.0.0
  • Basic Usage
    • Usage with create-react-app
    • Usage with Vite
    • Usage with Next.js
      Updated
    • Usage with Umi
    • Usage with Rsbuild
      New
  • Model Integration
    • OpenAI
    • Qwen
    • Others
  • Other
    • Contributing
    • FAQ

Qwen

Resources

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
ahooks-React Hooks Library
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

Tongyi Qianwen provides model inference services compatible with OpenAI.
Alibaba Cloud - Tongyi Qianwen

What is a "Service Compatible with OpenAI Models"?

It refers to a model inference service whose interface design and usage are consistent with OpenAI's API.

This means developers can use the same code and methods as they would for OpenAI models to interact with these compatible services, significantly reducing integration costs.

Method 1: Using useXAgent

This method is a ready-to-use solution for React environments provided by Ant Design X.

import { useXAgent } from '@ant-design/x';
// ... react env
const [agent] = useXAgent({
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen-plus',
// Use cautiously in production!
dangerouslyApiKey: 'DASHSCOPE_API_KEY',
});
function request() {
agent.request(
{
// Conversation messages
messages: [
{
role: 'user',
content: 'Hello',
},
],
// Enable streaming
stream: true,
},
{
// Success callback
onSuccess: (sseChunks) => {
// Triggered when the request completes
// This will contain the parsed sseChunks
},
onError: (error) => {
// Triggered in case of an error
},
onUpdate: (sse) => {
// Triggered during stream updates
// This will contain the parsed SSE object
},
},
);
}

Method 2: Using XRequest

This method is a ready-to-use solution for JavaScript environments provided by Ant Design X.

import { XRequest } from '@ant-design/x';
const xRequest = XRequest({
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen-plus',
// Use cautiously in production!
dangerouslyApiKey: 'DASHSCOPE_API_KEY',
});
function request() {
xRequest.create(
{
// Conversation messages
messages: [
{
role: 'user',
content: 'Hello',
},
],
// Enable streaming
stream: true,
},
{
// Success callback
onSuccess: (sseChunks) => {
// Triggered when the request completes
// This will contain the parsed sseChunks
},
onError: (error) => {
// Triggered in case of an error
},
onUpdate: (sse) => {
// Triggered during stream updates
// This will contain the parsed SSE object
},
},
);
}