Searching Internet Page with API 4.0

Hello,

I’m trying to search Wikipedia or other Websites for the latest articles.
It does not work with API 4.0.

If i am using ChatGPT 4.0 it is working perfect.

My Code is looking like following:


  public sendMessage(message: Messages[]): Promise<Messages> {
        return this.apiClient.chat.completions
          .create({
            messages: message as ChatCompletionMessageParam[],
            model: 'gpt-4',
          })
          .then((reponse) => {
            console.log(reponse);
            return reponse.choices[0].message as Messages;
          });
  }

Can someone help me please to find a solution?

Thank you a lot
Lars

1 Like

ChatGPT is different from the API. The former has integrated browsing capabilities while the latter hasn’t. To enable web search via the API you need to implement a function call and in your back-end then run a web search API (e.g. the Bing API). The results from this search can be integrated as context into the model prompt to generate the actual response.

To get started, you might want to take a look at the functional calling documentation here.

In the following post, I included an example function description for web search:

2 Likes

But why is it working in Playground?

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const response = await openai.chat.completions.create({
  model: "gpt-4-turbo",
  messages: [
    {
      "role": "assistant",
      "content": "Can you give me some information about this article https://de.wikipedia.org/wiki/Kulturapfel\n"
    },
    {
      "role": "assistant",
      "content": "The article on the provided link is about \"Kulturapfel,\" which refers to the cultivated apple (Malus domestica). It is from the German Wikipedia and discusses the domesticated apple, one of the most widely cultivated tree fruits. The apple tree originated in Central Asia, where its wild ancestor, Malus sieversii, is still found today. Apples have been grown for thousands of years in Asia and Europe and were brought to North America by European colonists. Apples have a wide range of uses including being eaten fresh, cooked into dishes, and fermented to make beverages like apple cider and vinegar.\n\nThe article likely details various aspects of apple cultivation, uses, nutritional facts, and perhaps some history and cultural significance of apples in different societies. If you need specific information from the article, feel free to ask!"
    },
    {
      "role": "assistant",
      "content": "Certainly! The article titled \"Kulturapfel\" on the German Wikipedia page is about the cultivated apple, scientifically known as Malus domestica. Here’s a summary of the main points from the article:\n\n1. **Origin and History**: The cultivated apple, Malus domestica, belongs to the family Rosaceae and is one of the most widely cultivated fruit trees. The majority of apple varieties that we consume today are derived from the wild apple Malus sieversii, originating from Central Asia, particularly Kazakhstan.\n\n2. **Cultivation and Spread**: Apples have been cultivated for thousands of years in Asia and Europe. They were introduced to America by European settlers. Today, apples are grown in temperate climates around the world and China is the leading producer.\n\n3. **Varieties**: There are more than 20,000 different varieties of apples, ranging in size, color, and taste. These varieties are used for various purposes, including cooking, eating raw, and producing cider.\n\n4. **Cultural Significance**: The article likely touches on the cultural significance of apples, seen in various traditions, myths, and symbols across different cultures.\n\n5. **Economic Value**: The apple industry is significant in many countries, providing economic value through both raw"
    }
  ],
  temperature: 1,
  max_tokens: 256,
  top_p: 1,
  frequency_penalty: 0,
  presence_penalty: 0,
});
1 Like

It’s not actually working. The assistant is returning an answer by drawing on existing knowledge and then “connecting the dots” based on the URL provided, which makes it clearly recognizable as a Wikipedia article. If you read between the lines then you can see that: For example in the second paragraph it reads "The article likely details …

3 Likes

Ah, good ol’ hallucinations. Playground models seem to annoyingly behave mildly differently from actual API calls, in this case the model simply hallucinates and believes it has access to the link.

3 Likes