UNPKG

langchain-xai

Version:

Grok API wrapper for Node.js

38 lines (37 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChatGrok = void 0; class ChatGrok { constructor(options) { this.apiKey = options.apiKey; this.model = options.model || "grok-beta"; this.temperature = options.temperature || 0.7; this.maxTokens = options.maxTokens || 1000; } async chat(input) { // Implementation will depend on Grok's API // This is a placeholder until you have the actual API details const response = await fetch("https://api.grok.x.ai/v1/chat", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apiKey}`, }, body: JSON.stringify({ model: this.model, messages: [{ role: "user", content: input }], temperature: this.temperature, max_tokens: this.maxTokens, }), }); const data = await response.json(); return data.choices[0].message.content; } async explain(input) { return this.chat(`Explain this: ${input}`); } async analyze(input) { return this.chat(`Analyze this: ${input}`); } } exports.ChatGrok = ChatGrok;