viho-llm 0.2.0 → 0.2.2

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/index.js CHANGED
@@ -47,11 +47,22 @@ const chat$1 = async (client, modelName, chatOptions) => {
47
47
 
48
48
  // gen
49
49
  const response = await client.models.generateContent(options);
50
- if (!response || !response.text) {
50
+ if (!response || !response.candidates?.[0]?.content) {
51
51
  logger$4.error(methodName, 'invalid response');
52
52
  return;
53
53
  }
54
54
 
55
+ // json
56
+ const rawText = response.candidates[0].content.parts[0].text;
57
+ if (options.generationConfig?.responseMimeType === 'application/json') {
58
+ try {
59
+ return JSON.parse(rawText);
60
+ } catch (e) {
61
+ logger$4.warn(methodName, 'Failed to parse JSON response', rawText);
62
+ return rawText;
63
+ }
64
+ }
65
+
55
66
  return response.text;
56
67
  } catch (error) {
57
68
  logger$4.error(methodName, 'error', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viho-llm",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Utility library for working with multiple LLM providers (Google Gemini and OpenAI), providing common tools and helpers for AI interactions",
5
5
  "keywords": [
6
6
  "llm",
@@ -68,5 +68,5 @@
68
68
  }
69
69
  }
70
70
  },
71
- "gitHead": "38f9238d5c59fe322424ee30e32037b44f6be7d8"
71
+ "gitHead": "ef48eb1271b731362a787945b2b4de35bdb27b6f"
72
72
  }
@@ -47,11 +47,22 @@ export const chat = async (client, modelName, chatOptions) => {
47
47
 
48
48
  // gen
49
49
  const response = await client.models.generateContent(options);
50
- if (!response || !response.text) {
50
+ if (!response || !response.candidates?.[0]?.content) {
51
51
  logger.error(methodName, 'invalid response');
52
52
  return;
53
53
  }
54
54
 
55
+ // json
56
+ const rawText = response.candidates[0].content.parts[0].text;
57
+ if (options.generationConfig?.responseMimeType === 'application/json') {
58
+ try {
59
+ return JSON.parse(rawText);
60
+ } catch (e) {
61
+ logger.warn(methodName, 'Failed to parse JSON response', rawText);
62
+ return rawText;
63
+ }
64
+ }
65
+
55
66
  return response.text;
56
67
  } catch (error) {
57
68
  logger.error(methodName, 'error', error);