Nodrex / Testomania

In practice more knowledge comes
https://play.google.com/store/apps/details?id=com.earth.testomania
Creative Commons Zero v1.0 Universal
49 stars 3 forks source link

ChatGPT AI API to answer Quiz #152

Open Nodrex opened 2 years ago

Nodrex commented 2 years ago

We could use ChatGPT AI API to find answers and unlock this button for users for 1Gel or something like that. What do you think guys?

Nodrex commented 1 year ago

There are a number of free language processing APIs that you can use in your Android app to ask questions and receive answers. Some options include:

IBM Watson Assistant: This API allows you to create chatbots and conversational interfaces for your apps. You can use it to ask questions and receive answers by interacting with a pre-trained conversation model.

Google Dialogflow: This API allows you to create chatbots and conversational interfaces for your apps. You can use it to ask questions and receive answers by interacting with a pre-trained conversation model.

OpenAI GPT-3: This API allows you to generate human-like text and perform other language-related tasks. You can use it to generate answers to questions, although the quality of the answers may vary depending on the complexity of the question.

Microsoft Azure Cognitive Services: This API offers a range of language processing capabilities, including natural language understanding, text translation, and text to speech. You can use it to ask questions and receive answers, although the quality of the answers may vary depending on the complexity of the question.

I hope this helps! Let me know if you have any questions or need further assistance.

Nodrex commented 1 year ago

To use the OpenAI API to ask a question and get an answer in a Kotlin Android app, you can use the /questions/completions endpoint of the OpenAI API. This endpoint allows you to submit a question and receive a list of possible completions for the question, along with scores indicating the likelihood of each completion.

Here is an example of how you can use the /questions/completions endpoint in a Kotlin Android app to ask a question and receive a list of possible answers:

import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response

class OpenAIClient(private val apiKey: String) {

    private val client = OkHttpClient()
    private val apiUrl = "https://api.openai.com/v1/questions/completions"

    fun askQuestion(question: String): String {
        val params = mapOf(
            "prompt" to question
        )

        val request = buildRequest(apiUrl, params)
        val response = client.newCall(request).execute()
        return if (response.isSuccessful) {
            response.body!!.string()
        } else {
            throw IOException("Failed to ask question: ${response.message}")
        }
    }

    private fun buildRequest(url: String, params: Map<String, String>): Request {
        val sb = StringBuilder(url)
        sb.append('?')
        params.forEach { (key, value) ->
            sb.append(key).append('=').append(value).append('&')
        }
        sb.setLength(sb.length - 1) // remove the last '&'

        return Request.Builder()
            .url(sb.toString())
            .addHeader("Authorization", "Bearer $apiKey")
            .build()
    }
}

To use the OpenAIClient class in your Kotlin Android app, you can instantiate an OpenAIClient object with your API key and then call the askQuestion() method to ask a question and receive a list of possible answers. For example:

val apiKey = "YOUR_API_KEY"
val client = OpenAIClient(apiKey)
val answer = client.askQuestion("What is the capital of France?")

The answer variable will contain a JSON string containing a list of possible completions for the question and their scores. You can parse this JSON string to extract the answers and their scores.

Nodrex commented 1 year ago

@shalva97 @kdiakonidze @Vazhapp Code and explanation text is generated by ChatGPT himself

Nodrex commented 1 year ago

Google Cloud Natural Language API is not free, but it does offer a free tier with a limited number of requests. You can use the free tier to try out the API and get a feel for how it works. The free tier includes 2,500 free requests per month, which is sufficient for many small projects and prototyping purposes.

If you need to make more requests than the free tier allows, you can purchase additional usage at a cost that varies based on the volume of requests and the features you use. Google Cloud also offers a variety of pricing plans and discounts for different use cases and volume levels.

To use Google Cloud Natural Language API in an Android app with Kotlin, you'll need to complete the following steps:

Set up a Google Cloud account: If you don't already have a Google Cloud account, you'll need to create one and sign up for the Natural Language API.

Enable the Natural Language API: Once you've signed up for a Google Cloud account, you'll need to enable the Natural Language API in the Google Cloud Console.

Create a service account: You'll need to create a service account and download the private key file to authenticate your API requests.

Set up the Google Cloud client library for Kotlin: You'll need to add the Google Cloud client library for Kotlin to your project dependencies. This library provides a convenient interface for making API requests and handling responses in Kotlin.

Make API requests: Once you've set up the client library and authenticated your API requests, you can start making API calls to the Natural Language API from your Android app.

Here's an example of how you might use the Natural Language API in an Android app with Kotlin:

import com.google.auth.oauth2.GoogleCredentials
import com.google.cloud.language.v1.Document
import com.google.cloud.language.v1.LanguageServiceClient
import com.google.cloud.language.v1.Sentiment

fun analyzeSentiment(text: String) {
    // Load the service account key file
    val credentials = GoogleCredentials.fromStream(FileInputStream("service-account.json"))

    // Create the Natural Language API client
    val languageServiceClient = LanguageServiceClient.create(credentials)

    // Create a document from the text
    val document = Document.newBuilder().setContent(text).setType(Document.Type.PLAIN_TEXT).build()

    // Analyze the sentiment of the document
    val sentiment = languageServiceClient.analyzeSentiment(document).documentSentiment

    // Print the sentiment score
    println("Sentiment score: ${sentiment.score}")

    // Close the client
    languageServiceClient.close()
}
Nodrex commented 1 year ago

IBM Watson Assistant is not free, but it does offer a free trial that allows you to try out the service and build a simple chatbot or conversational interface. The free trial includes 5,000 API calls per month, which is sufficient for many small projects and prototyping purposes.

To use IBM Watson Assistant in an Android app with Kotlin, you'll need to complete the following steps:

Set up an IBM Cloud account: If you don't already have an IBM Cloud account, you'll need to create one and sign up for IBM Watson Assistant.

Create a Watson Assistant service instance: Once you've signed up for an IBM Cloud account, you'll need to create a Watson Assistant service instance in the IBM Cloud Console.

Create a Watson Assistant workspace: You'll need to create a Watson Assistant workspace to define the behavior and logic of your chatbot or conversational interface.

Set up the Watson Assistant client library for Kotlin: You'll need to add the Watson Assistant client library for Kotlin to your project dependencies. This library provides a convenient interface for making API requests and handling responses in Kotlin.

Make API requests: Once you've set up the client library and authenticated your API requests, you can start making API calls to Watson Assistant from your Android app.

Here's an example of how you might use Watson Assistant in an Android app with Kotlin:

import com.ibm.cloud.sdk.core.security.IamAuthenticator
import com.ibm.watson.assistant.v2.Assistant
import com.ibm.watson.assistant.v2.model.MessageOptions
import com.ibm.watson.assistant.v2.model.MessageResponse

fun sendMessage(text: String) {
    // Create the Watson Assistant client
    val authenticator = IamAuthenticator("<api-key>")
    val assistant = Assistant("<version-date>", authenticator)
    assistant.serviceUrl = "<service-url>"

    // Set the assistant ID and message options
    val assistantId = "<assistant-id>"
    val options = MessageOptions.Builder(assistantId).inputText(text).build()

    // Send the message and get the response
    val response: MessageResponse = assistant.message(options).execute().getResult()

    // Print the response text
    println(response.output.generic[0].text)

    // Close the client
    assistant.close()
}
Nodrex commented 1 year ago

Microsoft Azure Text Analytics API is not free, but it does offer a free tier with a limited number of requests. You can use the free tier to try out the API and get a feel for how it works. The free tier includes 5,000 free requests per month, which is sufficient for many small projects and prototyping purposes.

To use Microsoft Azure Text Analytics API in an Android app with Kotlin, you'll need to complete the following steps:

Set up a Microsoft Azure account: If you don't already have a Microsoft Azure account, you'll need to create one and sign up for the Text Analytics API.

Enable the Text Analytics API: Once you've signed up for a Microsoft Azure account, you'll need to enable the Text Analytics API in the Azure portal.

Create a service principal and authenticate: You'll need to create a service principal and authenticate your API requests using a client ID and client secret.

Set up the Azure client library for Kotlin: You'll need to add the Azure client library for Kotlin to your project dependencies. This library provides a convenient interface for making API requests and handling responses in Kotlin.

Make API requests: Once you've set up the client library and authenticated your API requests, you can start making API calls to the Text Analytics API from your Android app.

Here's an example of how you might use the Text Analytics API in an Android app with Kotlin:

import com.azure.core.http.HttpClient
import com.azure.core.http.HttpPipeline
import com.azure.core.http.policy.HttpLogDetailLevel
import com.azure.core.http.policy.HttpLogOptions
import com.azure.identity.ClientSecretCredentialBuilder
import com.azure.ai.textanalytics.TextAnalyticsClient
import com.azure.ai.textanalytics.TextAnalyticsClientBuilder
import com.azure.ai.textanalytics.models.AnalyzeSentimentResult
import com.azure.ai.textanalytics.models.DocumentSentiment
import com.azure.ai.textanalytics.models.SentimentConfidenceScores

fun analyzeSentiment(text: String) {
    // Set the service endpoint and key
    val endpoint = "<service-endpoint>"
    val key = "<api-key>"

    // Set the credentials
    val clientId = "<client-id>"
    val clientSecret = "<client-secret>"
    val tenantId = "<tenant-id>"
    val credential = ClientSecretCredentialBuilder()
        .clientId(clientId)
        .clientSecret(clientSecret)
        .tenantId(tenantId)
        .build()

    // Create the Text Analytics client
    val httpPipeline = HttpPipeline.builder()
        .policies(
            HttpLogOptions.getDefault().newBuilder()
                .setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)
                .build(),
            credential
        )
        .build()
    val client = TextAnalyticsClientBuilder()
        .endpoint(endpoint)
        .pipeline(httpPipeline)
        .buildClient()

    // Analyze the sentiment of the text
    val sentimentResult: AnalyzeSentimentResult = client.analyzeSentiment(text)
    val sentiment: DocumentSentiment = sentimentResult.documentSentiment
    val scores: SentimentConfidenceScores = sentiment.confidenceScores
    val score: Double = sentiment.score

    // Print the sentiment score
    println("Sentiment score: $score")

    // Close the client
    client.close()
}
Nodrex commented 1 year ago

AWS Lex is not free, but it does offer a free tier with a limited number of requests. You can use the free tier to try out the service and build a simple chatbot or conversational interface. The free tier includes 10,000 free requests per month, which is sufficient for many small projects and prototyping purposes.

To use AWS Lex in an Android app with Kotlin, you'll need to complete the following steps:

Set up an AWS account: If you don't already have an AWS account, you'll need to create one and sign up for AWS Lex.

Create an AWS Lex bot: Once you've signed up for an AWS account, you'll need to create an AWS Lex bot in the AWS Management Console.

Set up the AWS SDK for Kotlin: You'll need to add the AWS SDK for Kotlin to your project dependencies. This SDK provides a convenient interface for interacting with AWS services in Kotlin.

Make API requests: Once you've set up the SDK and authenticated your API requests, you can start making API calls to AWS Lex from your Android app.

Here's an example of how you might use AWS Lex in an Android app with Kotlin:

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.lexruntime.LexRuntimeClient
import software.amazon.awssdk.services.lexruntime.model.PostTextRequest
import software.amazon.awssdk.services.lexruntime.model.PostTextResponse

fun sendMessage(text: String) {
    // Set the AWS credentials and region
    val accessKeyId = "<access-key-id>"
    val secretAccessKey = "<secret-access-key>"
    val credentials = AwsBasicCredentials.create(accessKeyId, secretAccessKey)
    val region = Region.US_EAST_1

    // Set the bot alias and name
    val botAlias = "<bot-alias>"
    val botName = "<bot-name>"

    // Set the user ID
    val userId = "<user-id>"

    // Create the Lex runtime client
    val lexClient = LexRuntimeClient.builder()
        .credentialsProvider(StaticCredentialsProvider.create(credentials))
        .region(region)
        .build()

    // Create the request object
    val request = PostTextRequest.builder()
        .botName(botName)
        .botAlias(botAlias)
        .userId(userId)
        .inputText(text)
        .build()

    // Send the request and get the response
    val response: PostTextResponse = lexClient.postText(request)

    // Print the response text
    println(response.message())

    // Close the client
    lexClient.close()
}
Nodrex commented 1 year ago

Google Dialogflow is not free, but it does offer a free tier with a limited number of requests. You can use the free tier to try out the service and build a simple chatbot or conversational interface. The free tier includes 2 million free requests per month, which is sufficient for many small projects and prototyping purposes.

To use Google Dialogflow in an Android app with Kotlin, you'll need to complete the following steps:

Set up a Google Cloud account: If you don't already have a Google Cloud account, you'll need to create one and sign up for Dialogflow.

Create a Dialogflow agent: Once you've signed up for a Google Cloud account, you'll need to create a Dialogflow agent in the Dialogflow Console.

Set up the Dialogflow client library for Kotlin: You'll need to add the Dialogflow client library for Kotlin to your project dependencies. This library provides a convenient interface for making API requests and handling responses in Kotlin.

Make API requests: Once you've set up the client library and authenticated your API requests, you can start making API calls to Dialogflow from your Android app.

We need to find the code manually, ChatGPT was not able to write

Nodrex commented 1 year ago

OpenAI's GPT-3 (Generative Pre-trained Transformer 3) is not free, but it does offer a free tier with a limited number of requests. You can use the free tier to try out the service and build a simple chatbot or conversational interface. The free tier includes 50 free requests per day, which is sufficient for many small projects and prototyping purposes.

To use OpenAI's GPT-3 in an Android app with Kotlin, you'll need to complete the following steps:

Set up an OpenAI account: If you don't already have an OpenAI account, you'll need to create one and sign up for GPT-3.

Obtain an API key: Once you've signed up for an OpenAI account, you'll need to obtain an API key in order to make API requests to GPT-3.

Set up the OpenAI client library for Kotlin: You'll need to add the OpenAI client library for Kotlin to your project dependencies. This library provides a convenient interface for making API requests and handling responses in Kotlin.

Make API requests: Once you've set up the client library and authenticated your API requests, you can start making API calls to GPT-3 from your Android app.

Here's an example of how you might use GPT-3 in an Android app with Kotlin:

import com.openai.api.Client
import com.openai.api.GPT3Model
import com.openai.api.model.v1.CompletionRequest
import com.openai.api.model.v1.CompletionResponse

fun generateText(prompt: String) {
    // Set the API key
    val apiKey = "<api-key>"

    // Set the model name and prompt
    val model = "text-davinci-002"
    val prompt = prompt

    // Create the OpenAI client
    val client = Client.builder(apiKey).build()

    // Create the request object
    val request = CompletionRequest.builder()
        .model(model)
        .prompt(prompt)
        .build()

    // Send the request and get the response
    val response: CompletionResponse = client.completions().create(request)

    // Print the response text
    println(response.getChoices()[0].getText())

    // Close the client
    client.close()
}
Nodrex commented 1 year ago

We can integrate all of these AI APIs and choose randomly which one to use and we will not run out of free requests per month. What do you think guys? @Vazhapp @shalva97 @kdiakonidze

Nodrex commented 1 year ago

Al codes are generated by ChatGPT, so take it as a grain assault, of course code might not be totally correct, but at leas we have starting point

Nodrex commented 1 year ago

My idea Untitled drawing

Nodrex commented 1 year ago

Maybe be useful: https://www.linkedin.com/posts/christopherobereder_ai-data-jobs-activity-7022212750399430656-Zx6A?utm_source=share&utm_medium=member_desktop

Nodrex commented 1 year ago

https://matemarschalko.medium.com/chatgpt-in-an-ios-shortcut-worlds-smartest-homekit-voice-assistant-9a33b780007a

https://www.youtube.com/watch?v=sTeoEFzVNSc&t=40s

Nodrex commented 1 year ago

https://beta.openai.com/docs/guides/code/introduction

https://github.com/f/awesome-chatgpt-prompts

https://media.licdn.com/dms/document/C561FAQFbmaHehpwF_A/feedshare-document-pdf-analyzed/0/1674201027361?e=1675900800&v=beta&t=as9E4MnjzU8XTA3ZGe1Ppt5XwEYuFaU3s-9GMhSNe_g

In General for better results:

Keywords:

Nodrex commented 1 year ago

https://indiaai.gov.in/article/seven-best-artificial-intelligence-apis-in-2022

https://geekflare.com/ai-apis/

Nodrex commented 1 year ago

https://youtu.be/ZelhC1uhN7I

Nodrex commented 1 year ago

https://scale.com/blog/chatgpt-vs-davinci

Nodrex commented 1 year ago

https://www.freecodecamp.org/news/create-a-serverless-chatgpt-app/

Nodrex commented 1 year ago

https://www.youtube.com/watch?v=OLg2BKhwaSc

Nodrex commented 1 year ago

https://github.com/transitive-bullshit/bing-chat

https://techcrunch.com/2023/04/25/a-developer-exploited-an-api-flaw-to-provide-free-access-to-gpt-4/

shalva97 commented 1 year ago

აუ აქ რამდენი რამ დაგიწერია :დ

Nodrex commented 1 year ago

Still hope for this 😁