Kimi
imi
Properties used to connect to Moonshot AI Kimi.
kimi
- Type: {
model?: string,
temperature?: number,
max_tokens?: number,
top_p?: number,
frequency_penalty?: number,
presence_penalty?: number,
stop?: string | string[],
system_prompt?: string,
tools?: KimiTool[],
function_handler?: FunctionHandler
} - Default: {model: "moonshot-v1-8k"}
Connect to Moonshot AI's chat completion API.
model is the name of the Kimi model to be used by the API.
temperature controls the randomness of responses (0.0-2.0). Higher values produce more creative outputs.
max_tokens limits the maximum number of tokens in the generated response.
top_p controls diversity through nucleus sampling (0.0-1.0).
frequency_penalty reduces repetition by penalizing frequently used tokens (-2.0 to 2.0).
presence_penalty reduces repetition by penalizing tokens that have appeared (-2.0 to 2.0).
stop defines stop sequences that will halt generation when encountered.
system_prompt provides behavioral context and instructions to the model.
tools defines available function declarations for the model to call.
function_handler enables function calling capabilities for tool use.
Example
- Sample code
- Full code
<deep-chat
directConnection='{
"kimi": {
"key": "placeholder key",
"system_prompt": "You are a helpful assistant.",
"temperature": 0.7
}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
directConnection='{
"kimi": {
"key": "placeholder key",
"system_prompt": "You are a helpful assistant.",
"temperature": 0.7
}
}'
style="border-radius: 8px"
></deep-chat>
Use stream to stream the AI responses.
Vision Example
Upload images alongside your text prompts for visual understanding. These capabilities are only available for vision models such as moonshot-v1-8k-vision-preview or moonshot-v1-32k-vision-preview.
- Sample code
- Full code
<deep-chat
directConnection='{
"kimi": {
"key": "placeholder key",
"model": "moonshot-v1-8k"
}
}'
images="true"
camera="true"
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
directConnection='{
"kimi": {
"key": "placeholder key",
"model": "moonshot-v1-8k"
}
}'
images="true"
camera="true"
style="border-radius: 8px"
textInput='{"styles": {"container": {"width": "77%"}}}'
></deep-chat>
When sending images we advise you to set maxMessages to 1 to send less data and reduce costs.
Tool Calling
Kimi supports function calling functionality:
KimiTool
- Type: {
type: "function",
function:{
name: string,
description?: string,
parameters: object
}
}
Array describing tools that the model may call.
type must be "function" for function tools.
name is the name of the tool function.
description explains what the tool does and when it should be used.
parameters defines the parameters the tool accepts in JSON Schema format.
FunctionHandler
- Type: (
functionsDetails: FunctionsDetails) =>{response: string}[]|{text: string}
The actual function that the component will call if the model wants to use tools.
functionsDetails contains information about what tool functions should be called.
This function should either return an array of JSONs containing a response property for each tool function (in the same order as in functionsDetails)
which will feed it back into the model to finalize a response, or return a JSON containing text which will immediately display it in the chat.
Example
- Sample code
- Full code
// using JavaScript for a simplified example
chatElementRef.directConnection = {
kimi: {
tools: [
{
type: 'function',
function: {
name: 'get_current_weather',
description: 'Get the current weather in a given location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
unit: {type: 'string', enum: ['celsius', 'fahrenheit']},
},
required: ['location'],
},
},
},
],
function_handler: (functionsDetails) => {
return functionsDetails.map((functionDetails) => {
return {
response: getCurrentWeather(functionDetails.arguments),
};
});
},
key: 'placeholder-key',
},
};
// using JavaScript for a simplified example
chatElementRef.directConnection = {
kimi: {
tools: [
{
type: 'function',
function: {
name: 'get_current_weather',
description: 'Get the current weather in a given location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
unit: {type: 'string', enum: ['celsius', 'fahrenheit']},
},
required: ['location'],
},
},
},
],
function_handler: (functionsDetails) => {
return functionsDetails.map((functionDetails) => {
return {
response: getCurrentWeather(functionDetails.arguments),
};
});
},
key: 'placeholder-key',
},
};
function getCurrentWeather(location) {
location = location.toLowerCase();
if (location.includes('tokyo')) {
return JSON.stringify({location, temperature: '10', unit: 'celsius'});
} else if (location.includes('san francisco')) {
return JSON.stringify({location, temperature: '72', unit: 'fahrenheit'});
} else {
return JSON.stringify({location, temperature: '22', unit: 'celsius'});
}
}