Let's connect
Let's connect

Large Language Models: How to use open source alternatives to ChatGPT for Scala documentation

Picture of Joanna Sendorek, Senior Data Scientist

Joanna Sendorek

Senior Data Scientist
Picture of Paulina Żak, Senior ML Engineer

Paulina Żak

Senior ML Engineer

15 minutes read

gpt-4

Abstractive and extractive answering

Extractive answering involves the machine identifying and selecting a subset of text from the input document that directly answers the question. This approach results in more precise and specific answers. However, it struggles when the input text lacks a direct answer or when a rephrased response is more desirable. Abstractive answering omits those limitations, as the model answers the question with its own words. This approach elicits a more coherent response. However, it will sometimes produce an answer outside the given context.

bert-1
bert-2
flan-alpaca-large
msmarco-distilbert-base-v4
lang-chain

console

How to convert case class Person(name: String, surname: String) into Json?
--------------------------------------
ChatGPT
"You can use the ujson library's write method to convert a case class into JSON format. Here's an example:\n\n```scala\nimport ujson._\ncase class Person(name: String, surname: String)\nval person = Person(\"John\", \"Doe\")\nval json = write(person)\nprintln(json) // Prints out {\"name\":\"John\",\"surname\":\"Doe\"}\n```\n\nIn this example, we import the ujson library and define a case class called Person. We then create an instance of the Person class and use the write method to convert it into a JSON string. Finally, we print out the JSON string."
--------------------------------------
Openai da vinci
" You can use the ujson library to convert a case class into a JSON string. For example, you can use the ujson.write method to convert a Person instance into a JSON string:\n\nval person = Person(\"John\", \"Doe\")\nval jsonString = ujson.write(person)\nprintln(jsonString) // Prints out {\"name\":\"John\",\"surname\":\"Doe\"}"
--------------------------------------
flan t5 xl
"ujson.read(name) print(\"\"\"\"name\": \"Peter\", \"age\": 13\"\"\"\"\" )"
--------------------------------------
flan t5 xxl
"scala case class Person(name: String, surname: String) json"
--------------------------------------
gpt4all
You can define a Writer like this and use it in the help method. Then you need an implicit for Writes[Person]."
--------------------------------------
alpaca-t5-xl
"\"name\": \"Peter\", \"age\": 13\"\" "
--------------------------------------
declare-lab/flan-sharegpt-xl
""
--------------------------------------

console

You are going to create Questions and Answers based on fragments of Scala 3 documentation given in a context.
Requirements:
1. The documentation is in a markdown file, but in output, no markdown artefact should be presented.
2. The answer should come from the documentation fragment provided. Questions and answers should work standalone without previous information. 
3. Be short and precise.
4. The questions should be strictly technical and should answer common developers questions. Questions like: “What is the title of the document the information is taken from?” is not allowed
5. Replace demonstrative pronouns with use <DOC NAME> instead in phrases like “this document”
6. Questions and answers should make sense without context, no phrases like “given fragment”, “given document” 
If the fragment is from a larger document, you will be given a summarization of the whole document, but use it only for the context. Do not create questions based on summarization.
If you cannot extract at least 5 relevant and technical questions with answers from the context fragment, return <NO QUESTIONS GENERATED>
Example:
Q: What is @main annotation?
A: Method with `@main` annotation is an entry point to a program.
Q: How to write a test using a temporary file?
A: Use `FunFixture` from munit. eg val usingTempFile: FunFixture[os.Path] = FunFixture(setup = _ => os.temp(prefix = "file-tests"), teardown = tempFile => os.remove(tempFile)); usingTempFile.test(<name>){{ <your test> }}
Q: How to change the jvm version in Scala CLI?
A: You can use the --jvm flag `scala-cli --jvm 8 Main.scala`
Document name: [DOC NAME]
{f'Summarization: {summarization}' if summarization else ''}
Context fragment: 
{fragment.page_content}       .
Remember, If you cannot extract at least 5 relevant and technical answers from the context fragment return less than 5 questions or text<NO QUESTIONS GENERATED> 
Answers should come directly from the context fragment.
Create 5 questions with answers. Let's take it step by step. “””}

Curated by

Sebastian Synowiec

Liked the article?

Share it with others!

explore more on

Take the first step to a sustained competitive edge for your business

Get your free consultation

VirtusLab's work has met the mark several times over, and their latest project is no exception. The team is efficient, hard-working, and trustworthy. Customers can expect a proactive team that drives results.

Stephen Rooke
Stephen RookeDirector of Software Development @ Extreme Reach

VirtusLab's engineers are truly Strapi extensions experts. Their knowledge and expertise in the area of Strapi plugins gave us the opportunity to lift our multi-brand CMS implementation to a different level.

facile logo
Leonardo PoddaEngineering Manager @ Facile.it

VirtusLab has been an incredible partner since the early development of Scala 3, essential to a mature and stable Scala 3 ecosystem.

Martin_Odersky
Martin OderskyHead of Programming Research Group @ EPFL

The VirtusLab team's in-depth knowledge, understanding, and experience of technology have been invaluable to us in developing our product. The team is professional and delivers on time – we greatly appreciated this efficiency when working with them.

Michael_Grant
Michael GrantDirector of Development @ Cyber Sec Company