Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Service API Builder #1

Open
audioreworkvisions opened this issue May 25, 2024 · 0 comments
Open

Service API Builder #1

audioreworkvisions opened this issue May 25, 2024 · 0 comments

Comments

@audioreworkvisions
Copy link
Member

<title>GPTCoder</title>

fly with ai
    Send <script> const API_KEY = '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'; var messages = [ { role: 'system', content: 'Du bist ein Fullstack-Entwickler, bekannt als GPT-Codes, der in allen Aspekten der Softwareentwicklung von Frontend bis Backend kompetent ist. Du verfügst über tiefgreifendes technisches Wissen, ausgezeichnete Problemlösungsfähigkeiten, strategische Denkweise, hervorragende Programmierfertigkeiten und lieferst stets effiziente und optimierte Code-Lösungen.' } ];
        document.getElementById('inputField').addEventListener('keydown', function(event) {
            if (event.key === 'Enter') {
                event.preventDefault();
                generateResponse();
            }
        });
    
        async function generateResponse() {
            var inputText = document.getElementById('inputField').value;
            let chat = document.getElementById('chat');
            chat.innerHTML += `<li>You: ${inputText}</li>`;
            var sentMessages = [...messages];
            document.getElementById('inputField').value = '';
            messages.push({ role: "user", content: inputText });
            sentMessages.push({ role: "user", content: inputText });
            console.log(messages);
            console.log(sentMessages);
            const response = await fetch('https://api.openai.com/v1/chat/completions', {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "Authorization": `Bearer ${API_KEY}`,
                },
                body: JSON.stringify({
                    model: "gpt-4-turbo-2024-04.09",
                    messages: sentMessages,
                    temperature: 0.82,
                    max_tokens: 2150,
                }),
            });
    
            if (response.ok) {
                const data = await response.json();
                console.log(data);
                let outputText = data.choices[0].message.content;
                chat.innerHTML += `<li>GPTCoder: ${outputText}</li>`;
                messages.push({ role: "assistant", content: outputText });
            }
            else {
                console.error('Error: ${response.status}');
                return null;
            }
        }
    </script>
    
    # for free to join this conversation on GitHub. Already have an account? # to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant