Skip to content

Commit

Permalink
Create API_Llama
Browse files Browse the repository at this point in the history
Signed-off-by: Josef Edwards <joed6834@colorado.edu>
  • Loading branch information
bearycool11 authored Nov 15, 2024
1 parent b2a9441 commit 96d77f9
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions API_Llama
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define GITHUB_API_URL "api.github.com"
#define GITHUB_API_PORT 443
#define CROSS_TALK_URL "localhost"
#define CROSS_TALK_PORT 8080

// Function to create a new socket
int create_socket() {
int sockfd;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("socket");
exit(1);
}
return sockfd;
}

// Function to set up the server address
void set_up_server_address(struct sockaddr_in* server_addr, char* url, int port) {
server_addr->sin_family = AF_INET;
server_addr->sin_port = htons(port);
inet_pton(AF_INET, url, &server_addr->sin_addr);
}

// Function to connect to the GitHub API
void connect_to_github_api(int sockfd, struct sockaddr_in* server_addr) {
if (connect(sockfd, (struct sockaddr*)server_addr, sizeof(*server_addr)) < 0) {
perror("connect");
exit(1);
}
}

// Function to connect to the cross-talk server
void connect_to_cross_talk_server(int sockfd, struct sockaddr_in* server_addr) {
if (connect(sockfd, (struct sockaddr*)server_addr, sizeof(*server_addr)) < 0) {
perror("connect");
exit(1);
}
}

// Function to send a request to the GitHub API
void send_request(int sockfd, char* request) {
send(sockfd, request, strlen(request), 0);
}

// Function to receive a response from the GitHub API
void receive_response(int sockfd, char* response) {
recv(sockfd, response, 1024, 0);
}

// Function to send a message to the cross-talk server
void send_message_to_cross_talk_server(int sockfd, char* message) {
send(sockfd, message, strlen(message), 0);
}

// Function to receive a response from the cross-talk server
void receive_response_from_cross_talk_server(int sockfd, char* response) {
recv(sockfd, response, 1024, 0);
}

int main() {
int github_sockfd, cross_talk_sockfd;
struct sockaddr_in github_server_addr, cross_talk_server_addr;

// Create a new socket for the GitHub API
github_sockfd = create_socket();

// Set up the server address for the GitHub API
set_up_server_address(&github_server_addr, GITHUB_API_URL, GITHUB_API_PORT);

// Connect to the GitHub API
connect_to_github_api(github_sockfd, &github_server_addr);

// Create a new socket for the cross-talk server
cross_talk_sockfd = create_socket();

// Set up the server address for the cross-talk server
set_up_server_address(&cross_talk_server_addr, CROSS_TALK_URL, CROSS_TALK_PORT);

// Connect to the cross-talk server
connect_to_cross_talk_server(cross_talk_sockfd, &cross_talk_server_addr);

// Send a request to the GitHub API
char* request = "GET /repos/bearycool11/pmll HTTP/1.1\r\nHost: api.github.com\r\n\r\n";
send_request(github_sockfd, request);

// Receive a response from the GitHub API
char response[1024];
receive_response(github_sockfd, response);
printf("%s", response);

// Send a message to the cross-talk server
char* message = "Hello, ChatGPT!";
send_message_to_cross_talk_server(cross_talk_sockfd, message);

// Receive a response from the cross-talk server
char cross_talk_response[1024];
receive_response_from_cross_talk_server(cross_talk_sockfd, cross_talk_response);
printf("%s", cross_talk_response);

// Close the sockets
close(github_sockfd);
close(cross_talk_sockfd);

return 0;
}

0 comments on commit 96d77f9

Please sign in to comment.