Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Open AI gibt mir keine Antwort

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Open AI gibt mir keine Antwort

    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      babl last edited by babl

      Hi zusammen, um das ganze java script gedöns ein wenig zu lernen und mit hilfe von chatgpt wollte ich einfach was testen, aber leider bleibe ich seit tagen auf dem gleichen stand.

      Habe folgendes Script:

      const axios = require('axios');
      
      const openaiApiKey = '********';
      
      async function fetchFromOpenAI() {
        const openaiUrl = 'https://api.openai.com/v1/chat/completions';
      
        const payload = {
          model: 'gpt-4o',
          messages: [
            { role: 'system', content: 'You are a helpful assistant.' },
            { role: 'user', content: 'Hello!' }
          ],
          temperature: 0.7
        };
      
        const headers = {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${openaiApiKey}`
        };
      
        try {
          const response = await axios.post(openaiUrl, payload, { headers });
          console.log('Full response from OpenAI:', JSON.stringify(response.data, null, 2));
          const messageContent = response.data.choices[0].message.content;
          console.log('Message content:', messageContent);
        } catch (error) {
          console.error('Error fetching data from OpenAI:', error.message);
          console.error('Error details:', error.response ? error.response.data : error.stack);
        }
      }
      
      fetchFromOpenAI();
      
      

      ich bekomme einfach keine Antwort, es bleibt leer, führe ich das script bei repl.it aus, läuft alles wunderbar, kann mir da jemand auf die sprünge helfen.

      Full response from OpenAI: {
        "id": "chatcmpl-9tH40n66aIIbVlCaTz50Ys9UK7LgV",
        "object": "chat.completion",
        "created": 1722960660,
        "model": "gpt-4o-2024-05-13",
        "choices": [
          {
            "index": 0,
            "message": {
              "role": "assistant",
              "content": "Hi there! How can I assist you today?"
            },
            "logprobs": null,
            "finish_reason": "stop"
          }
        ],
        "usage": {
          "prompt_tokens": 19,
          "completion_tokens": 10,
          "total_tokens": 29
        },
        "system_fingerprint": "fp_3aa7262c27"
      }
      Message content: Hi there! How can I assist you today?
       
      
      

      Was kann das sein?

      Version 8.7.6 vom Javascript Adapter

      Node.js: v20.16.0
      NPM: 10.8.1
      

      Habe auch schon etliche Logs mit eingebaut:

      const axios = require('axios');
      
      const openaiApiKey = '*******';
      
      async function fetchFromOpenAI() {
        const openaiUrl = 'https://api.openai.com/v1/chat/completions';
      
        const payload = {
          model: 'gpt-4o',
          messages: [
            { role: 'system', content: 'You are a helpful assistant.' },
            { role: 'user', content: 'Hello!' }
          ],
          temperature: 0.7
        };
      
        const headers = {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${openaiApiKey}`
        };
      
        try {
          console.log('Sending request to OpenAI with the following details:');
          console.log('URL:', openaiUrl);
          console.log('Payload:', JSON.stringify(payload, null, 2));
          console.log('Headers:', JSON.stringify(headers, null, 2));
      
          const response = await axios.post(openaiUrl, payload, { headers });
      
          // Prüfen, ob response definiert ist
          if (response) {
            console.log('HTTP Status Code:', response.status || 'No status code');
            console.log('Headers:', JSON.stringify(response.headers, null, 2) || 'No headers');
            console.log('Received response from OpenAI');
            console.log('Full response from OpenAI:', JSON.stringify(response.data, null, 2) || 'No data');
      
            if (response.data && response.data.choices && response.data.choices.length > 0) {
              const messageContent = response.data.choices[0].message.content;
              console.log('Message content:', messageContent);
            } else {
              console.log('Unexpected response structure or no choices found.');
            }
          } else {
            console.log('No response received from OpenAI');
          }
        } catch (error) {
          console.error('Error fetching data from OpenAI:', error.message);
          if (error.response) {
            console.error('Error details:', JSON.stringify(error.response.data, null, 2));
          } else {
            console.error('Error stack:', error.stack);
          }
        }
      }
      
      fetchFromOpenAI();
      
      

      Es kommt nur das zurück:

      javascript.1	18:27:10.044	info	script.js.common.Energiemanager.test: HTTP Status Code:
      javascript.1	18:27:10.044	info	script.js.common.Energiemanager.test: Headers:
      javascript.1	18:27:10.044	info	script.js.common.Energiemanager.test: Received response from OpenAI
      javascript.1	18:27:10.044	info	script.js.common.Energiemanager.test: Full response from OpenAI:
      javascript.1	18:27:10.044	info	script.js.common.Energiemanager.test: Message content:
      
      Jey Cee 1 Reply Last reply Reply Quote 0
      • Jey Cee
        Jey Cee Developer @babl last edited by

        @babl console.log funktiniert so nicht im Adapter. Der hat da eine eine eigene Funktion:
        log('was auch immer ' + deinErgebnis)

        B 1 Reply Last reply Reply Quote 1
        • B
          babl @Jey Cee last edited by

          @jey-cee OK danke das probier ich dann mal.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          966
          Online

          31.9k
          Users

          80.1k
          Topics

          1.3m
          Posts

          2
          3
          271
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo