Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
New http-request agent (LangStream#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Oct 9, 2023
1 parent 1d4aa48 commit da06daf
Show file tree
Hide file tree
Showing 18 changed files with 837 additions and 20 deletions.
19 changes: 19 additions & 0 deletions examples/applications/http-request-processor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Http Request processor

This sample application shows how to execute the http request processor.


## Deploy the LangStream application
```
./bin/langstream apps deploy test -app examples/applications/http-request-processor -i examples/instances/kafka-kubernetes.yaml
```

## Chat

Since the application opens a gateway, we can use the gateway API to send and consume messages using the use gateway `chat` feature:
```
./bin/langstream gateway chat test -g chat
```

Ask about a city and you will get the timezone.

23 changes: 23 additions & 0 deletions examples/applications/http-request-processor/gateways.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
#
# Copyright DataStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

gateways:
- id: chat
type: chat
chat-options:
answers-topic: output-topic
questions-topic: input-topic
52 changes: 52 additions & 0 deletions examples/applications/http-request-processor/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright DataStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

topics:
- name: "input-topic"
creation-mode: create-if-not-exists
- name: "output-topic"
creation-mode: create-if-not-exists
pipeline:
- name: "convert-to-json"
type: "document-to-json"
input: "input-topic"
configuration:
text-field: "city"
- name: "Get timezone info from geocoding API"
type: "http-request"
configuration:
url: "https://geocoding-api.open-meteo.com/v1/search"
query-string:
name: "{{{ value.city }}}"
count: "1"
format: "json"
output-field: "value.response"
method: "GET"

- name: "Extract timezone"
type: "compute"
configuration:
fields:
- name: "value.timezone"
expression: "value.response.results[0].timezone"
type: STRING

- name: "Extract timezone"
type: "drop-fields"
output: "output-topic"
configuration:
fields:
- response
92 changes: 92 additions & 0 deletions langstream-agents/langstream-agent-http-request/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>langstream-agents</artifactId>
<groupId>ai.langstream</groupId>
<version>0.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>langstream-agent-http-request</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>langstream-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>langstream-agents-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.samskivert</groupId>
<artifactId>jmustache</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-nar-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<classifier>nar</classifier>
</configuration>
<executions>
<execution>
<id>default-nar</id>
<phase>package</phase>
<goals>
<goal>nar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit da06daf

Please sign in to comment.