Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
fix AI models
Browse files Browse the repository at this point in the history
Signed-off-by: PranavPurwar <[email protected]>
  • Loading branch information
PranavPurwar committed Jul 12, 2023
1 parent 5ca0c62 commit a8aff1f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 43 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ChatProvider {
val jsonObject = mapOf("messages" to messages)
val messagesJson = gson.toJson(jsonObject)
println(messagesJson)
val url = "https://gpt4free-experimental.pranavpurwar.repl.co/chat/completions/$model"
val url = "https://gpt4free-experimental.pranavpurwar.repl.co/chat/$model"

val mediaType = "application/json; charset=utf-8".toMediaType()
val request = Request.Builder().url(url).post(messagesJson.toRequestBody(mediaType)).build()
Expand All @@ -41,7 +41,6 @@ object ChatProvider {
return try {
val response = client.newCall(request).execute()
val body = response.body.string()
println(body)
body
} catch (e: Exception) {
e.printStackTrace()
Expand Down
53 changes: 32 additions & 21 deletions app/src/main/kotlin/org/cosmicide/rewrite/fragment/ChatFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import java.time.Duration
class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {

private val conversationAdapter = ConversationAdapter()
private var model = Models.YQCLOUD
private var model = Models.THEB

// The client will expire in an hour.
// If you were thinking of using this key, don't. It's free already, just get your own.
Expand Down Expand Up @@ -78,26 +78,31 @@ class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {
"Google Bard"
}

R.id.model_vercel -> {
model = Models.VERCEL_GPT3_5
R.id.model_aichat -> {
model = Models.AICHAT
"Vercel"
}

R.id.model_forefront -> {
model = Models.FOREFRONT
R.id.model_aitianhu -> {
model = Models.AITIANHU
"Ora"
}

R.id.model_yqcloud -> {
model = Models.YQCLOUD
R.id.model_easychat -> {
model = Models.EASYCHAT
"Yqcloud"
}

R.id.model_phind -> {
model = Models.PHIND
R.id.model_h2o -> {
model = Models.H2O
"Phind"
}

R.id.model_theb -> {
model = Models.THEB
"Theb"
}

else -> return@setOnMenuItemClickListener false
}

Expand All @@ -122,23 +127,28 @@ class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {
val reply = when (model) {
Models.BARD -> client.ask(message).markdown()

Models.VERCEL_GPT3_5 -> ChatProvider.generate(
"vercel",
Models.AICHAT -> ChatProvider.generate(
"aichat",
conversationAdapter.getConversations()
)

Models.AITIANHU -> ChatProvider.generate(
"aitianhu",
conversationAdapter.getConversations()
)

Models.FOREFRONT -> ChatProvider.generate(
"forefront",
Models.EASYCHAT -> ChatProvider.generate(
"easychat",
conversationAdapter.getConversations()
)

Models.YQCLOUD -> ChatProvider.generate(
"yqcloud",
Models.H2O -> ChatProvider.generate(
"h2o",
conversationAdapter.getConversations()
)

Models.PHIND -> ChatProvider.generate(
"phind",
Models.THEB -> ChatProvider.generate(
"theb",
conversationAdapter.getConversations()
)
}
Expand Down Expand Up @@ -192,10 +202,11 @@ class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {

enum class Models {
BARD,
VERCEL_GPT3_5,
YQCLOUD,
FOREFRONT,
PHIND,
AICHAT,
AITIANHU,
EASYCHAT,
H2O,
THEB
}

private val Int.dp: Int
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/res/menu/chat_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@
android:title="Google Bard" />

<item
android:id="@+id/model_yqcloud"
android:title="Yqcloud GPT-3.5" />
android:id="@+id/model_aichat"
android:title="AIChat GPT-3.5" />

<item
android:id="@+id/model_vercel"
android:title="Vercel GPT-3.5" />
android:id="@+id/model_aitianhu"
android:title="AItianhu GPT-3.5" />

<item
android:id="@+id/model_forefront"
android:title="ForeFront GPT-3.5" />
android:id="@+id/model_easychat"
android:title="Easychat GPT-3.5" />

<item
android:id="@+id/model_phind"
android:title="Phind GPT-4" />
android:id="@+id/model_h2o"
android:title="H2O llama-13b" />

<item
android:id="@+id/model_theb"
android:title="TheB GPT-3.5" />
</menu>
15 changes: 13 additions & 2 deletions app/src/test/java/org/cosmicide/rewrite/chat/ChatProviderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ class ChatProviderTest {
mapOf("author" to "user", "text" to "hi"),
mapOf("author" to "bot", "text" to "hello")
)
val output = ChatProvider.generate("ora", conversation)
assert(output.isNotEmpty() && !output.contains("Error"))
val models = arrayOf(
"acytoo",
"aichat",
"ails",
"altianhu",
"chatgptai",
"chatgptlogin",
"deepai"
)
for (model in models) {
val output = ChatProvider.generate(model, conversation)
println(output)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.cosmicide.rewrite.editor.formatter

import org.cosmicide.rewrite.editor.formatter.ktfmtFormatter
import org.junit.Test

class ktfmtFormatterTest {
Expand All @@ -19,28 +18,28 @@ class ktfmtFormatterTest {
val foo = "bar"
}
""".trimIndent()
val formattedCode = KtfmtFormatter.formatCode(code)
assertThat("fun main() {\n val foo = \"bar\"\n}\n").isEqualTo(formattedCode)
val formattedCode = ktfmtFormatter.formatCode(code)
assert("fun main() {\n val foo = \"bar\"\n}\n" == formattedCode)
}

@Test
fun `should not modify already formatted code`() {
val code = "fun main() {\n val foo = \"bar\"\n}\n"
val formattedCode = KtfmtFormatter.formatCode(code)
assertThat(code).isEqualTo(formattedCode)
val formattedCode = ktfmtFormatter.formatCode(code)
assert(code == formattedCode)
}

@Test
fun `should handle code with syntax errors`() {
val code = "foo bar"
val formattedCode = KtfmtFormatter.formatCode(code)
assertThat(code).isEqualTo(formattedCode)
val formattedCode = ktfmtFormatter.formatCode(code)
assert(code == formattedCode)
}

@Test
fun `should handle empty input`() {
val input = ""
val formattedCode = KtfmtFormatter.formatCode(input)
assertThat("").isEqualTo(formattedCode)
val formattedCode = ktfmtFormatter.formatCode(input)
assert("" == formattedCode)
}
}

0 comments on commit a8aff1f

Please sign in to comment.