Skip to content

Instantly share code, notes, and snippets.

@maxandersen
Created October 6, 2023 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxandersen/36db042c573e36ff4f5e05d40d4c1cb0 to your computer and use it in GitHub Desktop.
Save maxandersen/36db042c573e36ff4f5e05d40d4c1cb0 to your computer and use it in GitHub Desktop.
//DEPS dev.langchain4j:langchain4j:0.23.0
//DEPS dev.langchain4j:langchain4j-open-ai:0.23.0
//DEPS org.slf4j:slf4j-simple:2.0.9
//JAVA_OPTIONS -Dorg.slf4j.simpleLogger.defaultLogLevel=debug
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import static dev.langchain4j.model.openai.OpenAiModelName.*;
import static java.time.Duration.ofSeconds;
public class _01_ModelParameters {
public static void main(String[] args) {
// parameter meaning for openAI explained here https://platform.openai.com/docs/api-reference/chat/create
ChatLanguageModel model = OpenAiChatModel.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
.modelName(GPT_4)
.temperature(0.8)
.timeout(ofSeconds(120))
.logRequests(true)
.logResponses(true)
.build();
String prompt = "Explain in one line how to make a beautiful painting";
String response = model.generate(prompt);
System.out.println(response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment