Skip to content

Getting started code for chatModel throws error #3105

@gsans

Description

@gsans

Following the code here.

The output is:

ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'message')
TypeError: Cannot read properties of undefined (reading 'message')
    at base.js:185:34

Looking at "base.js"

    /**
     * Makes a single call to the chat model.
     * @param messages An array of BaseMessage instances.
     * @param options The call options or an array of stop sequences.
     * @param callbacks The callbacks for the language model.
     * @returns A Promise that resolves to a BaseMessage.
     */
    async call(messages, options, callbacks) {
        const result = await this.generate([messages.map(coerceMessageLikeToMessage)], options, callbacks);
        const generations = result.generations;
        return generations[0][0].message;
    }

Not sure how to proceed as this is failing after adding the code from the docs.

Respone from Network looks good

{
  "id": "chatcmpl-8FkXETihLHC5MAjReDMqY7rNR2ddh",
  "object": "chat.completion",
  "created": 1698764492,
  "model": "gpt-4-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Rainbow Steps Socks Co."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 22,
    "completion_tokens": 7,
    "total_tokens": 29
  }
}

package.json

    "langchain": "^0.0.150",

For reference original code:

import { Component } from '@angular/core';
import { environment } from '../environments/environment.development';
import { ChatOpenAI } from 'langchain/chat_models/openai';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  title = 'chatbot';

  async call() {
    const chatModel = new ChatOpenAI({
      modelName: "gpt-4",
      temperature: 0.9,
      openAIApiKey: environment.OPENAI_API_KEY,
    });
    const text = 'What would be a good company name for a company that makes colorful socks?';
    const chatModelResult = await chatModel.predict(text);
    console.log(chatModelResult);
  }
}

Metadata

Metadata

Assignees

Labels

auto:bugRelated to a bug, vulnerability, unexpected error with an existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions