-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : adds workflow and expose endpoints for chat
- Loading branch information
1 parent
cc9452e
commit fdb1bd8
Showing
8 changed files
with
213 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: chatmodel-springai CI Build | ||
|
||
on: | ||
push: | ||
paths: | ||
- "chatmodel-springai/**" | ||
branches: [main] | ||
pull_request: | ||
paths: | ||
- "chatmodel-springai/**" | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
|
||
jobs: | ||
build: | ||
name: Run Unit & Integration Tests | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: chatmodel-springai | ||
strategy: | ||
matrix: | ||
distribution: [ 'temurin' ] | ||
java: [ '21' ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
|
||
- name: Set up JDK ${{ matrix.java }} | ||
uses: actions/[email protected] | ||
with: | ||
java-version: ${{ matrix.java }} | ||
distribution: ${{ matrix.distribution }} | ||
cache: 'maven' | ||
- name: Build and analyze | ||
run: ./mvnw clean verify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: pgvector-springai CI Build | ||
|
||
on: | ||
push: | ||
paths: | ||
- "pgvector-springai/**" | ||
branches: [main] | ||
pull_request: | ||
paths: | ||
- "pgvector-springai/**" | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
|
||
jobs: | ||
build: | ||
name: Run Unit & Integration Tests | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: pgvector-springai | ||
strategy: | ||
matrix: | ||
distribution: [ 'temurin' ] | ||
java: [ '21' ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
|
||
- name: Set up JDK ${{ matrix.java }} | ||
uses: actions/[email protected] | ||
with: | ||
java-version: ${{ matrix.java }} | ||
distribution: ${{ matrix.distribution }} | ||
cache: 'maven' | ||
- name: Build and analyze | ||
run: ./mvnw clean verify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
chatmodel-springai/src/main/java/com/example/ai/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.ai; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
chatmodel-springai/src/main/java/com/example/ai/controller/ChatController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.example.ai.controller; | ||
|
||
import org.springframework.ai.chat.ChatClient; | ||
import org.springframework.ai.chat.ChatResponse; | ||
import org.springframework.ai.chat.messages.SystemMessage; | ||
import org.springframework.ai.chat.messages.UserMessage; | ||
import org.springframework.ai.chat.prompt.Prompt; | ||
import org.springframework.ai.chat.prompt.PromptTemplate; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/api/ai") | ||
public class ChatController { | ||
|
||
private final ChatClient chatClient; | ||
|
||
ChatController(ChatClient chatClient) { | ||
this.chatClient = chatClient; | ||
} | ||
|
||
@GetMapping("/chat") | ||
Map<String,String> chat(@RequestParam String question) { | ||
var response = chatClient.call(question); | ||
return Map.of("question", question, "answer", response); | ||
} | ||
|
||
@GetMapping("/chat-with-prompt") | ||
Map<String,String> chatWithPrompt(@RequestParam String subject) { | ||
PromptTemplate promptTemplate = new PromptTemplate("Tell me a joke about {subject}"); | ||
Prompt prompt = promptTemplate.create(Map.of("subject", subject)); | ||
ChatResponse response = chatClient.call(prompt); | ||
String answer = response.getResult().getOutput().getContent(); | ||
return Map.of( "answer", answer); | ||
} | ||
|
||
@GetMapping("/chat-with-system-prompt") | ||
Map<String,String> chatWithSystemPrompt(@RequestParam String subject) { | ||
SystemMessage systemMessage = new SystemMessage("You are a sarcastic and funny chatbot"); | ||
UserMessage userMessage = new UserMessage("Tell me a joke about " + subject); | ||
Prompt prompt = new Prompt(List.of(systemMessage, userMessage)); | ||
ChatResponse response = chatClient.call(prompt); | ||
String answer = response.getResult().getOutput().getContent(); | ||
return Map.of( "answer", answer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
spring.threads.virtual.enabled=true | ||
|
||
spring.ai.openai.api-key=demo | ||
spring.ai.openai.base-url=http://langchain4j.dev/demo/openai | ||
spring.ai.openai.chat.options.model=gpt-3.5-turbo | ||
spring.ai.openai.chat.options.temperature=0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters