intention-coding 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +73 -29
- package/dist/utils/openai.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2027,38 +2027,79 @@ flowchart TD
|
|
|
2027
2027
|
class OpenAIService {
|
|
2028
2028
|
async generateText(params) {
|
|
2029
2029
|
const { prompt, temperature, system_prompt } = params;
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2030
|
+
let lastError = null;
|
|
2031
|
+
try {
|
|
2032
|
+
const response = await fetch(this.baseUrl, {
|
|
2033
|
+
method: 'POST',
|
|
2034
|
+
headers: {
|
|
2035
|
+
'Content-Type': 'application/json',
|
|
2036
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
2037
|
+
},
|
|
2038
|
+
body: JSON.stringify({
|
|
2039
|
+
model: this.model,
|
|
2040
|
+
messages: [
|
|
2041
|
+
...system_prompt ? [
|
|
2042
|
+
{
|
|
2043
|
+
role: 'system',
|
|
2044
|
+
content: system_prompt
|
|
2045
|
+
}
|
|
2046
|
+
] : [],
|
|
2040
2047
|
{
|
|
2041
|
-
role: '
|
|
2042
|
-
content:
|
|
2048
|
+
role: 'user',
|
|
2049
|
+
content: prompt
|
|
2043
2050
|
}
|
|
2044
|
-
]
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2051
|
+
],
|
|
2052
|
+
max_tokens: 65536,
|
|
2053
|
+
temperature,
|
|
2054
|
+
stream: false
|
|
2055
|
+
})
|
|
2056
|
+
});
|
|
2057
|
+
if (!response.ok) {
|
|
2058
|
+
const errorText = await response.text();
|
|
2059
|
+
throw new Error(`OpenAI API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
2060
|
+
}
|
|
2061
|
+
const data = await response.json();
|
|
2062
|
+
if (!data.choices || 0 === data.choices.length) throw new Error('No choices returned from OpenAI API');
|
|
2063
|
+
return data.choices[0].message.content;
|
|
2064
|
+
} catch (error) {
|
|
2065
|
+
lastError = error;
|
|
2066
|
+
try {
|
|
2067
|
+
const response = await fetch(this.kimiBaseUrl, {
|
|
2068
|
+
method: 'POST',
|
|
2069
|
+
headers: {
|
|
2070
|
+
'Content-Type': 'application/json',
|
|
2071
|
+
Authorization: `Bearer ${this.kimiApiKey}`
|
|
2072
|
+
},
|
|
2073
|
+
body: JSON.stringify({
|
|
2074
|
+
model: this.kimiModel,
|
|
2075
|
+
messages: [
|
|
2076
|
+
...system_prompt ? [
|
|
2077
|
+
{
|
|
2078
|
+
role: 'system',
|
|
2079
|
+
content: system_prompt
|
|
2080
|
+
}
|
|
2081
|
+
] : [],
|
|
2082
|
+
{
|
|
2083
|
+
role: 'user',
|
|
2084
|
+
content: prompt
|
|
2085
|
+
}
|
|
2086
|
+
],
|
|
2087
|
+
max_tokens: 65536,
|
|
2088
|
+
temperature,
|
|
2089
|
+
stream: false
|
|
2090
|
+
})
|
|
2091
|
+
});
|
|
2092
|
+
if (!response.ok) {
|
|
2093
|
+
const errorText = await response.text();
|
|
2094
|
+
throw new Error(`Kimi API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
2095
|
+
}
|
|
2096
|
+
const data = await response.json();
|
|
2097
|
+
if (!data.choices || 0 === data.choices.length) throw new Error('No choices returned from Kimi API');
|
|
2098
|
+
return data.choices[0].message.content;
|
|
2099
|
+
} catch (kimiError) {
|
|
2100
|
+
throw lastError;
|
|
2101
|
+
}
|
|
2058
2102
|
}
|
|
2059
|
-
const data = await response.json();
|
|
2060
|
-
if (!data.choices || 0 === data.choices.length) throw new Error('No choices returned from OpenAI API');
|
|
2061
|
-
return data.choices[0].message.content;
|
|
2062
2103
|
}
|
|
2063
2104
|
async generateStream(params) {
|
|
2064
2105
|
const { prompt, model, temperature, system_prompt } = params;
|
|
@@ -2176,6 +2217,9 @@ flowchart TD
|
|
|
2176
2217
|
_define_property(this, "apiKey", 'sk-d535ca964a434f20898150f77d6cdb2a');
|
|
2177
2218
|
_define_property(this, "baseUrl", 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions');
|
|
2178
2219
|
_define_property(this, "model", 'qwen3-coder-plus');
|
|
2220
|
+
_define_property(this, "kimiApiKey", 'sk-fp8wJSigZBEP3x8y6MAZWGPuVIHJ5PDZtX9lMQQk8hjP2R0u');
|
|
2221
|
+
_define_property(this, "kimiBaseUrl", 'https://api.moonshot.cn/anthropic');
|
|
2222
|
+
_define_property(this, "kimiModel", 'kimi-k2-0711-preview');
|
|
2179
2223
|
}
|
|
2180
2224
|
}
|
|
2181
2225
|
const openAIService = new OpenAIService();
|
package/dist/utils/openai.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export declare class OpenAIService {
|
|
|
17
17
|
private apiKey;
|
|
18
18
|
private baseUrl;
|
|
19
19
|
private model;
|
|
20
|
+
private kimiApiKey;
|
|
21
|
+
private kimiBaseUrl;
|
|
22
|
+
private kimiModel;
|
|
20
23
|
constructor();
|
|
21
24
|
generateText(params: OpenAIParams): Promise<string>;
|
|
22
25
|
generateStream(params: OpenAIParams): Promise<AsyncIterable<string>>;
|