Android Question Access DeepSeek A.I. example. Has anyone made a DeepSeek Webview solution?

I am amazed how little can be found on this forum about DeepSeek A.I. Here is my B4A solution to chatting with DeepSeek.
You have to add the attached deepseek1.txt file to DirAssets
This requires the use of your DeepSeek ApiKey. Does anyone have a Webview (or other) solution to chat with DeepSeek's playground (which is free of charge)?

B4X:
Sub Process_Globals
End Sub

Sub Globals
End Sub

'Information about DeepSeek:
'https://api-docs.deepseek.com/
'https://api-docs.deepseek.com/quick_start/pricing/
'https://platform.deepseek.com/usage            'token-usage
'https://platform.deepseek.com/transactions

Sub Activity_Create(FirstTime As Boolean)
    DEEPSEEK1("How high is the Eiffel Tower and where is its location?")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub DEEPSEEK1(text As String)
    Dim apiKey As String = "sk-4.....[Your DeepSeek Api Key]"
    Dim Job1 As HttpJob
    Dim Body, Result1 As String
    Dim n, m, Ticks1 As Long
 
    Ticks1 = DateTime.now
    Body = File.ReadString(File.DirAssets,"deepseek1.txt")
    Body = Body.Replace("##",text)
 
    Job1.Initialize("Job1", Me)                                        'See also: https://platform.openai.com/docs/api-reference/chat/create
    Job1.PostString("https://api.deepseek.com/chat/completions", Body)
    Job1.GetRequest.SetContentType("application/json")
    Job1.GetRequest.SetHeader("Authorization", "Bearer " & apiKey)

    Wait For (Job1) JobDone (Job1 As HttpJob)
    If Job1.Success Then
      Result1 = Job1.GetString
      Log(Result1)
      n = Result1.IndexOf2("content" & Chr(34) & ":",20)+10
      m = Result1.IndexOf2(Chr(34),n+1)
      If m>n And n>0 Then Result1 = Result1.SubString2(n, m)
      Result1 = Result1.Replace("\n",CRLF)
      Result1 = Result1.Replace("###", CRLF).Replace("**","")
      Log("   ")
      Log(Result1)                'DeepSeek's reply
      Log("Done in: " & (DateTime.Now - Ticks1) & " msec.")
    Else
      Log("Job1 failed")
    End If
End Sub
 

Attachments

  • deepseek1.txt
    206 bytes · Views: 109
Last edited:
Top